我把头撞在墙上 - 我有一个基本上空的测试文件(测试我的构建文件比其他任何东西更多
几个月前我的构建文件被破坏了 - 由于某种原因启动一个新项目没有解决它,所以我不得不从头做一个,最初它只需要支持构建,但现在它需要测试 - 它不工作:(
package com.rcdc.questiondatabase;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class RCDCServiceTest {
public RCDCServiceTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
@Test
public void testHelloTest() {
if(true){
assertTrue(true);
}
}
}
我的构建文件:
<?xml version="1.0" encoding="UTF-8"?>
<project name="INCAP" default="default" basedir=".">
<description>Builds, tests, and runs the project INCAP.</description>
<property name="build.dir" value="war/WEB-INF/classes"/>
<property name="dist.dir" value="dist"/>
<property name="test.dir" value="test"/>
<property name="test.build.dir" value="testbuild"/>
<path id="project.classpath">
<pathelement path="war/WEB-INF/classes" />
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<pathelement path="${java.home}/../lib/tools.jar:${libs.jsp-compiler.classpath}:${libs.jsp-compilation.classpath}"/>
</path>
<path id="project.test.classpath">
<pathelement path="war/WEB-INF/classes" />
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<pathelement path="${java.home}/../lib/tools.jar:${libs.jsp-compiler.classpath}:${libs.jsp-compilation.classpath}"/>
</path>
<target name="copyjars" description="Copies the App Engine JARs to the WAR.">
</target>
<target name="clean">
<delete dir="war/WEB-INF/classes"/>
</target>
<target name="compile" depends="copyjars" description="Compiles Java source and copies other source files to the WAR.">
<mkdir dir="${build.dir}" />
<copy todir="${build.dir}">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
<property name="myclasspath" refid="project.classpath"/>
<echo message="Classpath ${myclasspath}" />
<javac
srcdir="src"
destdir="${build.dir}"
classpathref="project.classpath"
debug="on" />
</target>
<target name="compiletest" depends="compile" description="compile the tests " >
<mkdir dir="${test.build.dir}" />
<javac
srcdir="test"
destdir="${test.build.dir}"
classpathref="project.test.classpath"
debug="on" />
</target>
<target name="dist" depends="compile">
<mkdir dir="war/WEB-INF/classes" />
<copy todir="war/WEB-INF/classes">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
<property name="myclasspath" refid="project.classpath"/>
</target>
<target name="test" depends="compiletest" description="run the tests " >
<junit printsummary="yes" fork="yes" haltonfailure="yes">
<formatter type="plain"/>
<batchtest fork="true">
<fileset dir="${test.dir}">
<include name="**/*Test*.java"/>
</fileset>
</batchtest>
<classpath refid="project.test.classpath" />
</junit>
</target>
<target name="test-single" depends="compiletest" description="Run a single test">
<fail unless="browser.context" message="Property not set: 'test-class'"/>
<echo message=" -- Running single test --"/>
<echo message=" -- ${browser.context} --" />
<junit printsummary="yes" fork="yes" showoutput="yes" haltonfailure="yes">
<formatter type="plain"/>
<batchtest fork="true">
<fileset dir="test">
<include name="${javac.includes}"/>
</fileset>
</batchtest>
<classpath refid="project.classpath" />
</junit>
</target>
</project>
答案 0 :(得分:0)
您的测试类路径似乎没有您的测试类,因此尽管Ant知道它应该运行哪些测试名称,但JUnit无法找到要运行的关联类。
从你的后续评论中 - 当Netbeans直接执行测试时,它会调用它自己的JUnit运行器,它带有关联的侦听器 - 或结果解析器 - 挂钩到JUnit生命周期,因此知道测试正在做什么。当你告诉Netbeans运行Ant任务时,它不知道Ant正在做什么(它没有看到Ant中的任务),所以不知道你是否正在尝试运行JUnit任务,或者在Ant中的许多其他任务之一,除了在控制台中尝试和报告之外是没有意义的。