Simple use on Junit

2008-02-23 09:33:59来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

Junit is a simple tool for test. It is easy to learn. You can find a book called Action In JUnit , but as a beginned you just need to know some basic use of it.

You build a class extends TestCase, add as many public void test methos as you want, with test begin, for instance

public class TestXXXX{

public void testXXX(){
// you code
}

}

in the code part you can use any Java code, including System.out.printn() to print information, or use assertXXXX() method JUnit provide.

When you use Runner to eun the test, use Runner.run(TestXXXX.class) in one main method in one class or use command line method.

You also can use TestSuite to add TestCase togather. use add method., you can build a testAll class and add a method as:

public class TestAll{

public static Test Suite(){
TestSuite suit=new TestSuite();
suite.addTestCase(TestXXXX.class); // or suite.add(new TestXXXX());
// add othe TestCases
return suite
}

}

Then you can use Runner.run(TestAll.class) to run all TestCase classes in the suite.

Actually, TestCase and TestSuite all emplements the Test interface, it is a composite pattern, so you also can ass TestSuite to another TestSuite and run it.

It is a easy way to use JUnit.and i think it is enough for simple programe. For more complex use, you can find another reference, such Action in junit, which i mentioned at first. It introduce some response, reauest test as a Http protocal, and other self-developed Test Classes. That's a interesting anduseful book.

上一篇: JAgileSearch to be born
下一篇: JBPM-Getting Started

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JAgileSearch to be born

下一篇:WEB2.0的商业之道 给整个互联网产生新的价值