2017-05-04 93 views
0

我正在IntelliJ IDE中开发Java应用程序。为了能够将我的repo连接到Travis CI,我使用IDE生成了ant build.xml。但IntelliJ尚未在构建文件中创建测试目标。我已经手动添加编辑了下列文件:Ant JUnit抛出ClassNotFoundException

<target name="test" depends="compile.module.pearplanner.tests"> 
    <junit> 
     <classpath> 
      <pathelement location="lib/junit-4.12.jar"/> 
     </classpath> 
     <batchtest> 
      <fileset dir="./Test/"> 
       <include name="**/*Test*" /> 
      </fileset> 
     </batchtest> 
     <formatter type="brief" usefile="false"/> 
    </junit> 
</target> 

当我运行

ant test 

我收到以下错误:

test: 
[junit] Testsuite: Model.AccountTest 
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec 
[junit] 
[junit] Null Test: Caused an ERROR 
[junit] Model.AccountTest 
[junit] java.lang.ClassNotFoundException: Model.AccountTest 
[junit]  at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
[junit]  at java.lang.Class.forName0(Native Method) 
[junit]  at java.lang.Class.forName(Class.java:348) 
[junit] 
[junit] 
[junit] Test Model.AccountTest FAILED 
[junit] Testsuite: Model.PersonTest 
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec 
[junit] 
[junit] Null Test: Caused an ERROR 
[junit] Model.PersonTest 
[junit] java.lang.ClassNotFoundException: Model.PersonTest 
[junit]  at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
[junit]  at java.lang.Class.forName0(Native Method) 
[junit]  at java.lang.Class.forName(Class.java:348) 
[junit] 
[junit] 
[junit] Test Model.PersonTest FAILED 
BUILD SUCCESSFUL 
Total time: 0 seconds 

My project structure

我已经测试多次我可以在网上找到的方法,但他们都给了我相同的输出。我在这里做错了什么?

+0

您的课程在哪里需要测试?将其添加到类路径中。 – Rao

回答

0

我设法解决它。原来,我不得不在类路径中指定类输出目录和测试类输出目录。此外hamcrest-core-1.3.jar也不在其中。正确版本:

<target name="test" depends="build.modules" > 
    <junit haltonerror="yes" haltonfailure="yes"> 
     <classpath> 
      <pathelement location="${basedir}/lib/junit-4.12.jar"/> 
      <pathelement location="${basedir}/lib/hamcrest-core-1.3.jar"/> 
      <pathelement location="${pearplanner.output.dir}/"/> 
      <pathelement location="${pearplanner.testoutput.dir}/"/> 
     </classpath> 
     <batchtest> 
      <fileset dir="${pearplanner.testoutput.dir}"> 
       <include name="**/*Test*" /> 
      </fileset> 
     </batchtest> 
     <formatter type="brief" usefile="false"/> 
    </junit> 
</target> 
相关问题