Before starting build my Enigma simulator, I decided to use a Test-Driven Development (TDD) approach. Why? Because I believe that with TDD every programmer - including you - can produce more robust software, do easier refactoring, and meet the software specifications.
For those who never heard about TDD, it pretty much a different style of programming advocated by Kent Beck and David Astels, some really influential guys in the wild. Instead of writing your classes and methods and then testing it - either manually or with auxiliary scripts - to ensure it’s working, TDD states that we must write tests in the first place. TDD, can be resumed in three steps:
- Write the specifications of what you want in the format of an automated test and verify it fails
- Implement the functionality to make the test pass in the easiest possible way (as baby steps that are small but takes you there)
- Refactor the code to make it more simple, elegant, performatic, readable, reusable…
mocha is a test framework that runs on Node.js. It basically runs over your code looking for test functions, execute them in parallel, and output the passing and failing tests in a pretty output format. On the other hand,
chai is an assertion library. It pretty much offers three functions for asserting inside tests:
assert. You can find more information on these assertion styles in their docs.
After writing some code, that’s how I execute them:
$ mocha enigma.js
That’s it. With