是否有任何方法可以立即构建所有junit的测试用例?喜欢命令" rake test"上的" raby on rails on rails",所有测试类都被执行。对于Java,我看到了一些解决方案的解决方案。但是我想执行所有软件包的所有测试用例。是否可以?我应该如何在build.xml文件上执行?
您可以运行所有通过软件包名称或类名称过滤的特定测试或特定测试。这是从JUNIT任务手册中获取的<batchtest>
的示例:
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<pathelement location="${build.tests}"/>
<pathelement path="${java.class.path}"/>
</classpath>
<formatter type="plain"/>
<test name="my.test.TestCase" haltonfailure="no" outfile="result">
<formatter type="xml"/>
</test>
<batchtest fork="yes" todir="${reports.tests}">
<fileset dir="${src.tests}">
<include name="**/*Test*.java"/>
<exclude name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
您可以根据需要调整<include name=""/>
/<exclude name=""/>
元素,也可以添加更多Include/Defcule Elements。然后,您可以为<target name="all-tests"/>
,<target name="package-foo-tests"/>
等不同测试创建不同的ANT <target/>
s。
我无法添加评论,这就是为什么我要发布答案。
我认为您需要的是测试套件类。
类似于跟随的事情。
package com.emeter.test.predeploy.sdm.common;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import com.emeter.test.predeploy.sdm.svc.TestOutdatedComponentRpt;
import com.emeter.test.predeploy.sdm.svc.TestSubstationSvc;
import com.emeter.test.predeploy.sdm.svc.TestSvmComponentSvc;
import com.emeter.test.predeploy.sdm.svc.TestSvmNotificationSvc;
@RunWith(Suite.class)
@SuiteClasses({
TestSubstationSvc.class,
TestSvmComponentSvc.class,
TestSvmNotificationSvc.class,
TestOutdatedComponentRpt.class
}
)
public class TestSuite {
}
您可以从任何软件包中导入所需的类,然后一次运行它们。包含测试案例的课程置于"特征类"注释下。
编辑:您只需像Eclipse中的任何其他测试用例文件一样运行此操作。