写一个干净的junit4测试

时间:2010-09-16 16:24:28

标签: multithreading unit-testing junit4

使用junit测试,如何启动应用程序软件然后正确关闭它并为每次测试执行此操作?

  • @test public void test1(){// start appli //测试Jtextfield //关闭appli }
  • @test public void test2(){// start appli // test ComboBox // close appli}
  • @test public void test3 {// start appli // test Jbutton // close appli

}

1 个答案:

答案 0 :(得分:1)

通常有一些方法可以在测试类/测试方法传递到junit 4之前和之后执行一些操作(请参阅有关@BeforeClass和@BeforeMethod注释的信息,例如,此处:http://junit.sourceforge.net/javadoc/org/junit/BeforeClass.html

但是应用程序启动/停止行为看起来更接近功能测试,而不是单元测试。可能最好不要启动和停止整个应用程序,而是执行一些应用程序重新初始化。

此外,还有完善的功能测试框架TestNG(http://testng.org),它还提供了类似于beforeclass / beforemethod注释的方法。