もう一つの古典的なant junitの問題です。私がトピックで見つけた他の質問と同様に、おそらく微妙なクラスパスエラーですが、提案された解決策のどれも私のために働いていません。ここではEclipseでうまく動作します私のテストコードは、ある -Ant junitタスクのNoClassDefFoundError
package trial;
import java.net.MalformedURLException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import trial.CommonCode; //this is a library of methods, since the test runs I'm not including it here
public class BaseTests {
WebDriver driver;
CommonCode myCommon;
@Before
public void startup() throws MalformedURLException, InterruptedException{
myCommon=new CommonCode();
driver=myCommon.driver;
}
@After
public void cleanup(){
driver.quit();
}
@Test
public void deleteLists(){
System.out.println("Hi Mom!");
myCommon.loginLibrary("GAL");
}
}
そして、ここでは私のbuild.xmlです(クラスファイルは$ {WORKDIR} \ビン\裁判とソースファイルにある$ {WORKDIR}である\ SRC \裁判) -
<project default="main" basedir=".">
<property name="testbin" value="bin\trial"/>
<property name="src.dir" value="src\trial"/>
<path id="path.class">
<pathelement location="c:\Java\selenium-2.8.0" />
<pathelement location="C:\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705"/>
<pathelement location="C:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300"/>
<fileset dir="c:\Java\selenium-2.8.0" includes="*.jar" />
<fileset dir="C:\eclipse\plugins\org.junit_4.8.2.v4_8_2_v20110321-1705" includes="*.jar"/>
<fileset dir="C:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib" includes="*.jar"/>
<path refid="src.dir" />
</path>
<path id="src.dir">
<pathelement location="${src.dir}" />
</path>
<path id="test.dir">
<pathelement location="${testbin}"/>
</path>
<target name="main" depends="compile" description="main target">
<echo> Building now </echo>
</target>
<target name="compile" description="compilation target" >
<javac srcdir="${src.dir}" destdir="${testbin}" classpathref="path.class" debug="on" verbose="true"/>
</target>
<target name="runtest" >
<junit fork="no" printsummary="true" showoutput="true">
<classpath>
<path refid="path.class"/>
<path refid="test.dir"/>
<path refid="src.dir"/>
</classpath>
<formatter type="brief" usefile="false" />
<batchtest fork="yes">
<fileset dir="${testbin}">
<include name="*Tests.class"/>
</fileset>
</batchtest>
</junit>
</target>
</project>
私は、コマンドラインから、あるいはアリペイン日食からantタスクのRUNTESTを実行するかどうか、同じエラーが表示されます。
runtest:
[junit] Running BaseTests
[junit] Testsuite: BaseTests
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Null Test: Caused an ERROR
[junit] BaseTests (wrong name: trial/BaseTests)
[junit] java.lang.NoClassDefFoundError: BaseTests (wrong name: trial/BaseTests)
[junit] at java.lang.ClassLoader.defineClass1(Native Method)
[junit] at java.lang.ClassLoader.defineClassCond(Unknown Source)
[junit] at java.lang.ClassLoader.defineClass(Unknown Source)
[junit] at java.security.SecureClassLoader.defineClass(Unknown Source)
[junit] at java.net.URLClassLoader.defineClass(Unknown Source)
[junit] at java.net.URLClassLoader.access$000(Unknown Source)
[junit] at java.net.URLClassLoader$1.run(Unknown Source)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[junit] at java.lang.ClassLoader.loadClass(Unknown Source)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Unknown Source)
[junit] Test BaseTests FAILED
だから、正しいJUnitテストを見つけることです(trial.BaseTests)、それからh間違った名前として。感謝の意をもっていただいた提案、特にデバッグのヒントがありますので、今後この問題を回避することができます。
ファイルパスにさまざまなバリエーションを試しましたが、問題は解決しませんでした。私はtestbinの値をプレーンなバニラ "bin"に戻しましたが、まだテストが見つからないと主張しています。 junitが使用しているクラスパスを "エコー"する方法がありますか? (ところで、コンパイルタスクは正常に動作し、クラスファイルは想定されている場所に表示されます) – Sabrina
Arg。 **/* Tests.classになるようにファイルセットインクルードを変更しなければなりませんでした。今それは幸せです。ありがとう! – Sabrina