So first of all, why should we test? The best answer is actually: Life is to short for manual testing (it was actually the slogan at the Google London Test Automation Conference 2007.
Note the last if statement. This just defines what to export in nodejs.
To be able to run nodeunit tests on server we have to install node.js. Then we have to install nodeunit with npm globally:
npm install nodeunit -g
Then create a test file: TestCustomerModel.js:
Btw, here is my solution:
Next, run the test:
Allright, something is wrong:
Aha, we forgot the space. Let’s fix it:
And the test result is much better 😀
Nodeunit in web browser
nodeunit can be run in a web browser as well. I’ll test the same CustomerModel in this lab. Very simple stuff so far 😀
Change the Test.aspx:
When you deploy this as an aspx page, you’ll not see the test results, because nodeunit writes directly to body element, which is not rendered… We have to change nodeunit.js a little bit..
Then we can see the result on the page:
The whole solution for this lab can be found in my repo on github.