How to solve “Cause: the class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask was not found.” while running “ant test”?

前端 未结 5 1556
慢半拍i
慢半拍i 2021-01-01 13:31

I have a target named test and I want to do some tests.

I put here the important parts in build.xml. It includes:



        
5条回答
  •  囚心锁ツ
    2021-01-01 14:11

    When you run JUnit tasks, you must make sure both your classpath that was used for your builds, and the path for the junit jars are added to your classpath.

    I prefer to put the junit jars inside my project, so others don't have to install them in their machines for my build to work. I would install them in ${basedir}/antlib/junit

    I use ${basedir}/antlib to store all the various Ant build related jars such as the Ant-Contrib jars, JaCoCo, Findbugs, etc. Since this is inside my project, a checkout will always include these jars and the build will work for everyone:

     
        
    
    

    This will create a path that contains your JUnit jars. Now to compile your junit tests:

    
          
               
           
    

    Note that placing the JUnit jars in $ANT_HOME/lib main not work because it depends whether has includeAntRuntime set or not. It's always highly recommended not to have this set in order to make your build more platform independent.

    Also remember to include that junit.path in your task too.

提交回复
热议问题