jeudi 21 juillet 2016

Not able to run all junit tests in a category with ant

Background

I am trying to create an Ant script that:

  • compiles source files
  • compiles junit tests
  • runs junit tests of a certain category

Most of what I have done so far, have been taken from this question.

This is what I have in my ant script so far:

<?xml version="1.0"?>
<project name="junit_tests">
  <property name="build-main" location="build/main"/>
  <property name="build-test" location="build/main"/>
  <property name="src-test" value="java/test" />
  <property name="src-com" value="java/com" />
  <property name="src-lib" value="webapp/WEB-INF/lib" />
  <property name="test-lib" value="java/test/lib" />
  <path id="classpath">
    <fileset dir="${src-lib}" includes="*.jar"/>
    <fileset dir="${test-lib}" includes="*.jar" />
  </path>
  <path id="classpath.test">
    <path refid="classpath"/>
    <pathelement location="${build}"/>
  </path>
  <target name="init">
    <mkdir dir="${build-main}" />
    <mkdir dir="${build-test}" />
  </target>

  <target name="compileSrc" depends="init" description="compile src files ">
    <javac debug="on" destdir="${build-main}" encoding="UTF-8" fork="true" memorymaximumsize="1024m" includeantruntime="true">
      <src path="${src-com}" />
      <classpath refid="classpath"/>
    </javac>
    <javac debug="on" destdir="${build-main}" encoding="UTF-8" fork="true" memorymaximumsize="1024m" includeantruntime="true">
      <src path="${src-test}" />
      <classpath refid="classpath"/>
    </javac>
  </target>


  <!-- Test and build all files  -->
  <!-- To run this: use "ant" (default) or "ant run" -->
  <target name="run" depends="compileSrc">
    <junit printsummary="on" haltonfailure="no" fork="true">
        <classpath>
          <path refid="classpath.test" />
          <pathelement location="${build-test}"/>
        </classpath>
        <formatter type="xml" />
        <batchtest>
            <fileset dir="${build-main}" includes="**/NonDBTest.class" />
        </batchtest>
    </junit>
  </target>
</project>

Output from junit task

run: [junit] WARNING: multiple versions of ant detected in path for junit [junit] jar:file:/usr/local/Cellar/ant/1.9.7/libexec/lib/ant.jar!/org/apache/tools/ant/Project.class [junit] and jar:file:/Users/arnab/work/my_project/webapp/WEB-INF/lib/ant.jar!/org/apache/tools/ant/Project.class [junit] Running test.NonDBTest [junit] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.178 sec

BUILD SUCCESSFUL Total time: 37 seconds

Problem The test class that is in this category NonDBTest has a total of 7 tests, so junit is clearly not running all of them.

NonDBTest.java is just a interface with no methods, and this is what my test class looks like

@Category(NonDBTest.class)
public class MyTestClass extends AbstractTestCase{
....

@Test
public void testA(){ ... }

@Test
public void testB(){ ... }

@Test
public void testC(){ ... }

@Test
public void testD(){ ... }

@Test
public void testE(){ ... }

}

Question What am I doing wrong? I have tried changing NonTestDB to a class. I've tried implementing the interface but nothing has worked so far. How can I get junit to run all classes that are in the NonTestDB category? Am I missing something?

Aucun commentaire:

Enregistrer un commentaire