Best Practices & Recommodations

Best Practices

  1. If you wrap or decorate all external dependencies within a proxy layer, not only do you have an encapsulation layer for your control when communicating with dependencies, but you can also utilize this layer as your mocking layer. See the unit tests for an example application.
  2. For your true BDD Scenario tests, try to have the tests enter the application the same place a user would enter. For most services, this means the Controller Layer. Doing this allows you to test all layers of your code from a single unit test. Powerful!!
  3. All Scenario's are executed asynchronously. This means that every 'it' block will need to utilize the 'done' function to indicate the test is complete.
  4. NEVER use arrow functions in your test suites. When you use arrow functions for your 'it' and 'describe' blocks, the scope that gets binded to your 'this' context will the scope at the top of the context. In your test suite this is probably the top of your file. Why is that an issue? Because you will completely lose the ability to utilize all of the information Mocha places in its test scope (i.e. the 'this' context).

Recommendations

  1. If at all possible, your proxy layer should utilize a stateless pattern as it is easier to write and debug tests. For an example, see the testing layer in Maddox. Specifically this Stateless Proxy.
  2. Maddox uses itself to test itself. If you can't find an example in this documentation, please look at the tests for more detailed examples. That being said, please reach out to us if you have any issues, we would love to help you achieve great scenario coverage in your tests.