Junit和Ant集成的另一个简单问题

发布于 2024-09-14 19:57:29 字数 2756 浏览 6 评论 0原文

我无法从 build.xml 脚本运行 Junit 测试。我感觉我已经尝试了一切。

这是我的 build.xml 脚本。

 <property file="build.properties"/>
 <property name="src.dir" value="src"/>
 <property name="build.dir" value="classes"/>
 <property name="web.dir" value="war"/>
 <property name="test.dir" value="test"/>

 <path id="build.classpath">
     <fileset dir="lib">
      <include name="*.jar"/>
     </fileset>
     <!-- servlet API classes: -->
  <fileset dir="${appserver.lib}">
      <include name="servlet*.jar"/>
   </fileset>
   <pathelement path="${build.dir}"/>
  <pathelement path="${test.dir}"/>
</path>

 <path id="classpath.base"/>
 <path id="classpath.test">
 <pathelement location="c:/ant/lib/junit.jar" />
 <pathelement location="${build.dir}"/>
 <pathelement location="${src.dir}"/>
 <pathelement location="${test.dir}" />
 <path refid="classpath.base" />
 </path>

 <target name="build">
  <mkdir dir="${build.dir}"/>
  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"       deprecation="false" optimize="false" failonerror="true">
      <src path="${src.dir}"/>
      <classpath refid="build.classpath" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"/>
   </javac>
  </target>

<target name="test">
    <junit haltonfailure="true">
      <classpath refid="classpath.test" />
      <classpath refid="build.classpath"/>
      <formatter type="brief" usefile="false" />
      <test name="com.mmz.mvc.test.PracticeTest" />
    </junit>
  </target>

我从控制台收到以下错误消息。

test:
    [junit] Testsuite: com.mmz.mvc.test.PracticeTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Null Test:  Caused an ERROR
    [junit] com.mmz.mvc.test.PracticeTest
    [junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.PracticeTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:247)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\Eric\Documents\Java\mmz\WEB-INF\build.xml:44: Test com.mmz.mvc.test.PracticeTest failed

I can't get my Junit tests to run from my build.xml script. I feel like I have tried everything.

Here is my build.xml script.

 <property file="build.properties"/>
 <property name="src.dir" value="src"/>
 <property name="build.dir" value="classes"/>
 <property name="web.dir" value="war"/>
 <property name="test.dir" value="test"/>

 <path id="build.classpath">
     <fileset dir="lib">
      <include name="*.jar"/>
     </fileset>
     <!-- servlet API classes: -->
  <fileset dir="${appserver.lib}">
      <include name="servlet*.jar"/>
   </fileset>
   <pathelement path="${build.dir}"/>
  <pathelement path="${test.dir}"/>
</path>

 <path id="classpath.base"/>
 <path id="classpath.test">
 <pathelement location="c:/ant/lib/junit.jar" />
 <pathelement location="${build.dir}"/>
 <pathelement location="${src.dir}"/>
 <pathelement location="${test.dir}" />
 <path refid="classpath.base" />
 </path>

 <target name="build">
  <mkdir dir="${build.dir}"/>
  <javac destdir="${build.dir}" source="1.5" target="1.5" debug="true"       deprecation="false" optimize="false" failonerror="true">
      <src path="${src.dir}"/>
      <classpath refid="build.classpath" source="1.5" target="1.5" debug="true" deprecation="false" optimize="false" failonerror="true"/>
   </javac>
  </target>

<target name="test">
    <junit haltonfailure="true">
      <classpath refid="classpath.test" />
      <classpath refid="build.classpath"/>
      <formatter type="brief" usefile="false" />
      <test name="com.mmz.mvc.test.PracticeTest" />
    </junit>
  </target>

I am getting the following error message from the console.

test:
    [junit] Testsuite: com.mmz.mvc.test.PracticeTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Null Test:  Caused an ERROR
    [junit] com.mmz.mvc.test.PracticeTest
    [junit] java.lang.ClassNotFoundException: com.mmz.mvc.test.PracticeTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:247)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
    [junit]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)

BUILD FAILED
C:\Users\Eric\Documents\Java\mmz\WEB-INF\build.xml:44: Test com.mmz.mvc.test.PracticeTest failed

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天生の放荡 2024-09-21 19:57:29

我想出了如何让它运行我的测试,但现在它告诉我,我的测试成功了,即使它应该失败,我知道它失败了,因为我正在测试

assertTrue("Example doesnt work",false);

I figured out how to get it to run my tests, but now it is telling me that my test is successful even though it is supposed to fail, I know it fails because I am testing

assertTrue("Example doesnt work",false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文