【问题标题】:Ant JUnit Test case failure report not reporting testcase nameAnt JUnit 测试用例失败报告不报告测试用例名称
【发布时间】:2013-06-25 08:05:36
【问题描述】:

我正在解析使用 Ant Task 生成的 xml Junit 报告。我看到 pass 测试用例的报告显示了执行的测试用例(方法)的确切名称,但不是 failing 测试用例。

可以在下面验证....

<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>

【问题讨论】:

    标签: java testing selenium ant junit


    【解决方案1】:

    根据我的经验,没有附带测试用例属性的错误属性只有在测试爆炸时才会出现,就像它无法解析类时一样。这是一个例子......

      </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">
    

    【讨论】:

    • 虽然,测试用例名称是“com.gui.pool.ValidPoolTest” 我有兴趣获取方法的实际名称,例如测试通过时出现的名称。 ""
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-19
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    相关资源
    最近更新 更多