2013-06-27 174 views
0

我正在解析使用Ant任務生成的xml Junit報告。我看到pass測試用例報告顯示測試用例(方法)執行的確切名稱,但不適用於失敗測試用例。Ant JUnit測試用例失敗報告未報告測試用例名稱

下面可以驗證....

<testcase classname="com.gui.LoginTest" name="blankFieldsTest" time="2.222" /> 
    <testcase classname="com.gui.LoginTest" name="wrongUsernameOrPassword" time="2.233" /> 
    <testcase classname="com.gui.LoginTest" name="successfulLoginTest" time="13.12" /> 
    <testcase classname="junit.framework.TestSuite" name="com.gui.pool.ValidPoolTest" time="0.001"> 
    <error message="Error communicating with the remote browser. It may have died.&#xa;Build info: version: &apos;2.33.0&apos;, revision: &apos;4e90c97&apos;, time: &apos;2013-05-22 15:33:32&apos;&#xa;System info: os.name: &apos;Windows Server 2008 R2&apos;, os.arch: &apos;amd64&apos;, os.version: &apos;6.1&apos;, java.version: &apos;1.7.0_21&apos;&#xa;Driver info: driver.version: RemoteWebDriver" type="org.openqa.selenium.remote.UnreachableBrowserException">org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died. 
Build info: version: &apos;2.33.0&apos;, revision: &apos;4e90c97&apos;, time: &apos;2013-05-22 15:33:32&apos; 
System info: os.name: &apos;Windows Server 2008 R2&apos;, os.arch: &apos;amd64&apos;, os.version: &apos;6.1&apos;, java.version: &apos;1.7.0_21&apos; 
Driver info: driver.version: RemoteWebDriver 
</error> 
    </testcase> 

我想失敗的測試用例也出現在XML的名字,什麼是我應該使用的配置?

這裏是我的Ant任務看起來像

<target name="test.helper" description="executed the junit task on compiled code and creates .xml reports"> 
     <mkdir dir="${unit.test.dir}" /> 
     <junit dir="${unit.test.dir}" fork="yes" printsummary="on" haltonfailure="no"> 
      <batchtest fork="yes" todir="${unit.test.dir}"> 
       <fileset dir="${test.classes.dir}"> 
        <include name="**/TestSuite.class" /> 
       </fileset> 
      </batchtest> 
      <formatter type="xml" /> 
      <classpath> 
       <pathelement path="${test.classes.dir}" /> 
       <fileset id="distjars" dir="${dist.lib.dir}"> 
        <include name="**/*.jar" /> 
        <exclude name="**/*_test.jar" /> 
       </fileset> 
       <fileset id="selenium.jars" dir="${local.selenium.dir}/"> 
        <include name="**/*.jar" /> 
       </fileset> 
      </classpath> 
     </junit> 
    </target> 

回答

0

以我的經驗,唯一的一次你沒有附帶測試用例屬性錯誤屬性是當測試只是炸彈,因爲它何時能」解決課堂問題。下面是一個例子...

</properties> 

    <error message="thinClientTests.userTests.NewUserTest" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: thinClientTests.userTests.NewUserTest 
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) 
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) 
at java.security.AccessController.doPrivileged(Native Method) 
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:186) 

煩人,但因爲它是一個非功能性的測試反正自從參考必須固定,即使運行測試反正得到的結果我可以接受它。根據我在上面的示例中看到的,實際上您正在爲錯誤測試獲取測試用例名稱。包是「junit.framework」,類「TestSuite」,而你的實際測試名是「com.gui.pool.ValidPoolTest」。這是不是你所期望的?我無法驗證,但這裏是我得到一個錯誤,我可以驗證測試用例和錯誤的屬性正確地匹配起來......

<testcase classname="thinClientTests.permissionTests.SuperuserLoginMenuCheck" name="testSuperuserMenusFirefox" time="284.066"> 
     <error message="Error communicating with the remote browser. It may have died.&#xa;Build info: version: &apos;2.31.0&apos;, revision: &apos;1bd294d&apos;, time: &apos;2013-02-27 20:52:59&apos;&#xa;System info: os.name: &apos;Windows Server 2012&apos;, os.arch: &apos;x86&apos;, os.version: &apos;6.2&apos;, java.version: &apos;1.7.0_11&apos;&#xa;Driver info: driver.version: RemoteWebDriver" type="org.openqa.selenium.remote.UnreachableBrowserException"> 
+0

雖然,TestCase的名稱是「com.gui.pool .ValidPoolTest「我有興趣獲得方法的實際名稱,例如測試通過時顯示的名稱。 「」 – pratikch

相關問題