我想在 build 文件中实现运行测试程序,并输出 html 形式的报告,现在总报一个 java.lang.ClassNotFoundException: com.ktplay.testing.KTAllTestSuite 的错,但我程序中是有这个类的
错误 log 如下:
E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing>ant -buildfile build3.xml report
Buildfile: E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing\build3.xml
cleanReport:
[delete] Deleting directory E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing\report
test:
[mkdir] Created dir: E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing\report
[junit] Running com.ktplay.testing.KTAllTestSuite
[junit] Testsuite: com.ktplay.testing.KTAllTestSuite
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
[junit] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec
[junit]
[junit] Caused an ERROR
[junit] com.ktplay.testing.KTAllTestSuite
[junit] java.lang.ClassNotFoundException: com.ktplay.testing.KTAllTestSuite
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
[junit] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
[junit] at java.security.AccessController.doPrivileged(Native Method)
[junit] at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[junit] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[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:259)
[junit]
[junit] Test com.ktplay.testing.KTAllTestSuite FAILED
report:
[mkdir] Created dir: E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing\report\html
[junitreport] Processing E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing\report\TESTS-TestSuites.xml to C:\Users\KTplay\AppData\Local\Temp\null1510513641
[junitreport] Loading stylesheet jar:file:/D:/ant/apache-ant-1.9.4/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 285ms
[junitreport] Deleting: C:\Users\KTplay\AppData\Local\Temp\null1510513641
BUILD SUCCESSFUL
Total time: 1 second
E:\ktplay-android-sdk\sdk\ktplay_testing\ktplay_testing>
cmd 执行错误图片
我的 build3.xml 如下:
<target name="test" depends="cleanReport">
<mkdir dir="report" />
<junit printsummary="yes" haltonerror="no" haltonfailure="no" fork="yes">
<formatter type="plain" usefile="false" />
<formatter type="xml" />
<test name="com.ktplay.testing.KTAllTestSuite" todir="report" />
<classpath refid="JUnit 4.libraryclasspath" />
</junit>
</target>
<target name="report" depends="test">
<mkdir dir="report/html" />
<junitreport todir="report">
<fileset dir="report">
<include name="TEST-*.xml" />
</fileset>
<report todir="report/html" />
</junitreport>
</target>
<test name="com.ktplay.testing.KTAllTestSuite" todir="report" />
KTAllTestSuite 类如下
package com.ktplay.testing;
import junit.framework.Test;
import junit.framework.TestSuite;
import com.ktplay.testing.accountmanager.KTAccountManagerTestSuite;
import com.ktplay.testing.friendship.KTFriendshipTestSuite;
import com.ktplay.testing.leaderboard.KTLeaderboardTestSuite;
import com.ktplay.testing.login.KTLoginTest;
public class KTAllTestSuite
{
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTestSuite(KTLoginTest.class);
suite.addTest(KTAccountManagerTestSuite.suite());
suite.addTest(KTLeaderboardTestSuite.suite());
suite.addTest(KTFriendshipTestSuite.suite());
return suite;
}
}
代码结构如下图:
求大神帮忙看一下是什么问题
下图是最终生成的报告效果,如果正常运行,应该就是我要的效果了