Gradle - Java - tests - java.lang.AssertionError Assertion Error

时间:2013-08-30 21:55:06

标签: java unit-testing ant junit gradle

运行gradle构建。

编译工作正常,但在测试任务期间出现错误,即测试失败。

输出为:

com.tr.ids.biz.domain.TestAttributeDescriptorBeanProvider > testGetAttributeHandler FAILED
    java.lang.AssertionError at TestAttributeDescriptorBeanProvider.java:65

com.tr.ids.biz.domain.TestAttributeDescriptorBeanProvider > testGetSpringBeanWithExp FAILED
    java.lang.AssertionError at TestAttributeDescriptorBeanProvider.java:60




com.tr.ids.biz.domain.pvt.dao.TestRdbmsDAOFactory > testCreateDAO FAILED
    java.lang.AssertionError at TestRdbmsDAOFactory.java:90

83 tests completed, 3 failed
:test FAILED

如果您看到前两个失败的测试,那么Java失败()失败并且这些行的源代码Java文件快照是(忽略行#,因为我已经使用了can -n命令)。第60和65行给出了错误。我尝试将#60 + 61 + 62行连接到第60行,同时在gradle构建时出错:

-bash-3.2 $ cat -n test / java / com / tr / ids / biz / domain / TestAttributeDescriptorBeanProvider.java | egrep“* 6 [0-9] | 70”

60                          fail(BASE_NAME + ": Failed in 'setUp()' method: "
61                                          + exp.getMessage()
62                                          + exp.getCause());
63                  } catch (SvcMockLibException exp) {
64
65                          fail(BASE_NAME + ": Failed in 'setUp()' method: "
66                                          + exp.getMessage()
67                                          + exp.getCause());
68                  }
69
70          }

-bash-3.2 $

同样,第90行(显示第90,91,92行)的第2个文件失败,并包含以下代码:

assertEquals(
        "Test1: Returned bean is not instance of RdbmsAttributeDescriptorDAO",
        true, flag);

任何想法,为什么assertEquals()和fail()失败。

使用ANT编译时,相同的源代码有效并且不会产生这些错误。

执行单元测试部分的ANT代码是:

  <!-- Execute the UNIT tests -->
  <target name="test-junit" depends="init,classpaths,classpath-junit,compile-junit" >
    <property name="test.junit.reports" value="junit-test-reports" />
    <delete dir="${test.junit.reports}" />
    <mkdir dir="${test.junit.reports}" />
    <mkdir dir="${test.junit.reports}/xml" />

    <junit printsummary="yes" haltonfailure="no" failureproperty="build.test.failure" >
      <batchtest todir="${test.junit.reports}/xml" >
        <fileset dir="${build.junit.classes}">
          <include name="**/Test*.class" />
        </fileset>
      </batchtest>
      <classpath>
        <pathelement path="${test-junit.classpath}" />
      </classpath>
      <formatter type="xml" />
    </junit>
    <junitreport todir="${test.junit.reports}" >
      <fileset dir="${test.junit.reports}/xml" >
        <include name="TEST*.xml" />
      </fileset>
      <report format="frames" todir="${test.junit.reports}/html" />
    </junitreport>

    <fail if="build.test.failure" message="*** JUnit test cases did not pass. ***" />
  </target>

  <!-- Setup classpath for JUnit tests -->
  <target name="classpath-junit" depends="init" >
    <property name="build.src.java-junit" value="${build.home}/test/java" />
    <property name="build.src.rsrc-junit" value="${build.home}/test/resources" />
    <property name="build.junit.classes"  value="${build.dest}/junit/classes" />
    <path id="test-junit.classpath">
    <path location="${build.junit.classes}" />
    <path location="${build.dest.classes}" />
    <path refid="build.classpath" />
    <path location="${build.src.conf}" />
    <path location="${build.home}" />
    <path location="${build.src.rsrc-junit}" />
    </path>
    <property name="test-junit.classpath" refid="test-junit.classpath" />
  </target>

  <!-- Compile the JUnit source code -->
  <target name="compile-junit" depends="init,classpaths,classpath-junit,compile" >
    <delete dir="${build.junit.classes}"/>
    <mkdir dir="${build.junit.classes}"/>
    <javac
       destdir="${build.junit.classes}"
       debug="true"
       debuglevel="lines,vars,source"
       optimize="false"
       deprecation="${build.compiler.deprecation}">
       <classpath>
          <path refid="build.classpath" />
          <path refid="test-junit.classpath" />
       </classpath>
       <src path="${build.src.java-junit}"/>
    </javac>
  </target>

注意:当我为另一个项目尝试基于ANT的目标时,ANT / Gradle在单元测试中都失败了,因此ANT代码对Gradle中失败的一些项目的测试失败了。但是我上面给出的情况在ANT中运行良好并且在Gradle“gradle clean build”步骤中失败(其中build也调用:test task)。

0 个答案:

没有答案