How to do unit testing without the use of a library? -


i've never written single unit test. since every article read, talking unit testing. figured should started it.

but how?

can point me simple unit tested hello world example? without use of junit or likes.

if don't want use other libraries have lot of work yourself. example, suppose have class 1 function want test:

class foo {     public int bar(int input); } 

you can write test class:

class testfoo {     public void testbarpositive() {         foo foo = new foo();         system.out.println(foo.bar(5) == 7);     }      public void testbarnegative() {         foo foo = new foo();         system.out.println(foo.bar(-5) == -7);     }      public static void main(string[] args) {         testfoo t = new testfoo();         t.testbarpositive();         t.testbarnegative();     } } 

this basic example shows how write own unit tests.

that said, strongly recommend using library junit. gives lot free , removes huge amount of boiler-plate code have write yourself. generates nice reports , (when combined cobertura) can give comprehensive view of how complete testing is.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -