Hacker News new | ask | show | jobs
by Rodeva 4598 days ago
Assert driven testing means that the tests are part of the actual code that is running. It's helpful because when an assert fails, the stack trace is right at the position where it failed. In many ways it's an easy way to incorporate testing into your application without the need for an additional framework.

A simple example can be done by writing a single function in the root scope or some global function (javascript)

function assert(assertion, description) { if(!assertion) { console.log(description); //could also have other application error handling code } }

Then in a function in your application:

function myFunc() { var x = 1; assert(x == 1, "x does not equal 1 in myFunc()“);

\\Continue code... }

This is obviously a very simple example and can definitely be iterated upon, but it gets the basic point across and I'm on my phone so writing code isn't the easiest :-P

Some systems have something like this built in, such as node which has more features.

http://nodejs.org/api/assert.html