Junit和Ant集成的另一个简单问题
我无法从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出了如何让它运行我的测试,但现在它告诉我,我的测试成功了,即使它应该失败,我知道它失败了,因为我正在测试
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