I'm new to unit testing using the Mocha & should.js. I'm using the Mocha's BDD for testing my application. The application I'm testing has different components like account, products & order. Before moving the code to the git repository I want to test all aspects of the application. I've different test files for all the components. For example, account.js for account, order.js for order & so on.
I want to test all the components against a temporary test account. So the flow is:
My question is how do I make sure the temporary account is created before executing other tests?
Since I've test cases in different file how do I make sure they are executed in the same order as mentioned above? Is there any other better way to test the application?
Thanks.
Your unit tests should be independent: execution of one should not affect execution of the others. Using Mocha, I do this by having every test file require
a utilities file with a beforeEach
function that will clear the database, establish connections, etc., for every unit test. There is also an afterEach
function that cleans up and disconnects after every unit test.
If every single unit test that you will run requires a test account, you can set the test account in a similar top-level beforeEach
function. Otherwise, you can set up the test account in a beforeEach
function within the desired Mocha describe
blocks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With