Simple use on Junit
2008-02-23 09:33:59来源:互联网 阅读 ()
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
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash