Saturday, August 21, 2010

How to write Test cases in Java??Can anybody send me some example code??

It depends entirely on what you are testing.





Rawlyn.How to write Test cases in Java??Can anybody send me some example code??
For most stuff, you should use framework called JUnit. Check it out on http://www.junit.org


It is very easy to write a test case. Just make sure your unit test class extends TestCase. (TestCase is located in junit.jar):





class MyTestClass extends TestCase {


public void testMyStuff1() {


MyClass mc = new MyClass();


Object result = mc.doSomething();


Assert.notNull(result);


}


}





You can run tests by using either JUnit standalone client, which you can find on aforementioned website, or using your IDE, such as Eclipse or IntelliJ IDEA, which are preconfigured to run JUnit tests so that you don't have to worry about classpath issues.

No comments:

Post a Comment