1
使用ANT腳本運行JUnit測試時,一組測試(TestSCF)是所有測試的子集。這些測試將作爲每晚構建的一部分運行並生成報告。使用@IncludeCategory定義需要運行的測試,並使用ClasspathSuite來定位項目中的所有測試。JUnit報告未顯示使用類別和ANT時測試的所有類別
示例測試類聲明,定義爲作爲TestSCF子集運行。 TestSCF是一個空的界面。
@Category(TestSCF.class)
public class ErrorDialogTest extends TestCase
{
....
}
主測試套件。
@RunWith(Categories.class)
@IncludeCategory(TestSCF.class)
@SuiteClasses({AllTests.class})
public class SCFTests
{
}
的AllTests中聲明
@RunWith(ClasspathSuite.class)
public class AllTests
{
}
Ant腳本
<!-- Run the unit tests -->
<junit showoutput ="true"
printsummary = "yes"
fork = "yes"
timeout = "60000" >
<formatter type="xml"/>
<classpath refid="cpath"/>
<batchtest fork = "yes"
todir = "${test.report.dir}">
<fileset dir="${src.dir}">
<include name="**/SCFTests.java"/>
</fileset>
</batchtest>
</junit>
<!-- Copy the XML files that get deleted by junitreport -->
<mkdir dir="${junit.html.dir}/xml_files"/>
<copy todir="${junit.html.dir}/xml_files" preservelastmodified="true">
<fileset dir="${test.report.dir}">
<include name="*.xml"/>
</fileset>
</copy>
<!-- Format the test results into browsable HTML -->
<junitreport todir="${junit.html.dir}">
<fileset dir="${test.report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.html.dir}"/>
</junitreport>
的問題是,JUnit的報告顯示,只有一個類測試的相關部分 - SCFTests。我明白爲什麼會發生這種情況,但想知道是否有辦法爲每個實際測試的課程生成一份報告,或者想方設法將測試課程的名稱添加到測試結果的「名稱」中報告。
例如:
dev.sca.test.ErrorDialogTest 45 Passed, 3 Failures, 0 Errors
,而不是
SCFTests 45 Passed, 3 Failures, 0 Errors