我知道还有一些关于此主题在stackoverflow的其他问题。但是我正在寻找一个特定的答案 - 如果我使用JUnit,那么数据不能在不同类别中存在的测试之间共享。 例如一个初始化为零的静态变量计数器。我在@Test
方法中打印其值。然后在第二课的另一个@Test
中做同样的事情。我喜欢这个Selenium Webdriver的测试框架?
<target name="LoginTestAndPreReqs" depends="dist">
<mkdir dir="${java.test.reports.path}" />
<junit haltonfailure="no" printsummary="true">
<classpath>
<pathelement location = "${build}" />
</classpath>
<formatter type="xml"/>
<batchtest fork="yes" todir="${java.test.reports.path}">
<fileset dir="${build}/">
<include name="**/TestUnits.class"/>
<include name="**/TestUnits1.class"/>
<exclude name="**/*$*.class"/>
</fileset>
</batchtest>
</junit>
</target>
通过build.xml
调用都在这两个班的测试,但输出显示的计数器复位到每个TestUnit *方法零。这意味着计数器在这两个测试之间没有共享时递增。
现在,对于selenium
我使用的是webdriver
API。我想维护用于登录我的网站的驱动程序对象。当他们出现在不同的类中时,如何在不同的@Test
方法之间传递此驱动程序对象?用Junit
这似乎是不可能的。或者,也许我可能在build.xml
中做错了什么。似乎每个测试用例都在不同的JVM
中调用。