Organizing Tests Using Mocha & Should.js

I am new to unit testing using Mocha and should.js. I am using Mocha BDD to test my application. The application I'm testing has different components, such as account, products, and order. Before moving the code to the git repository, I want to check all aspects of the application. I have different test files for all components. For example, account.js for an account, order.js for an order, etc.

I want to test all components in a temporary test account. So the thread:

  • Create Test Account
  • Check all the functions associated with the account (update profile, change password, etc.)
  • Check all the functionality of the product account
  • Check all account functionality
  • Delete the test account and all information associated with it.

My question is, how do I get a temporary account to be created before performing other tests?

Since I have test cases in different files, how can I make sure they are executed in the same order as above? Is there any other better way to test the application?

Thanks.

+7
source share
1 answer

Your unit tests should be independent: the execution of one should not affect the execution of the others. Using Mocha, I do this by having each test file require a utility file with a beforeEach function that cleans the database, establishes connections, etc. For each unit test. There is also an afterEach function that clears and disables after each unit test.

If a test account is required for each unit test that you run, you can set up a test account in a similar top-level function beforeEach . Otherwise, you can set up a test account in the beforeEach function within the required Mocha describe blocks.

+7
source

All Articles