Difference between org.junit.Test and junit.framework.Test packages
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <project name="JunitSuite" basedir="." default="clean"> <property name="${src}" value="./src/JunitSuiteProject" /> <property name="${build}" value="./build" /> <property name="package" value="JunitSuiteProject"/> <property name="jar" value="./build/jar"/> <target name="clean"> <delete dir="./build"/> <mkdir dir="./build"/> <mkdir dir="./build/jar"/> </target> <target name="run"> <junit printsummary="yes" haltonfailure="yes" showoutput="yes"> <classpath location="C:\Program Files\Java\apache-ant-1.9.2\lib\selenium-server-standalone-2.35.0.jar"/> <classpath location="E:\Swaroop Don't Touch\Selenium\eclipse-jee-juno-SR2-win32\eclipse\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100\junit.jar"/> <classpath location="C:\Program Files\Java\apache-ant-1.9.2\lib\*.jar"/> <classpath location="E:\Swaroop Don't Touch\Selenium\eclipse-jee-juno-SR2-win32\eclipse\plugins"/> <formatter type="brief" usefile="false"/> <batchtest fork="yes"> <fileset dir="C:\Program Files\Java\apache-ant-1.9.2\lib" includes="selenium-server-standalone-2.35.0.jar"/> <fileset dir="E:\Swaroop Don't Touch\Selenium\eclipse-jee-juno-SR2-win32\eclipse\plugins\org.junit_3.8.2.v3_8_2_v20100427-1100" includes="junit.jar"/> <fileset dir="C:\Program Files\Java\apache-ant-1.9.2\lib" includes="*.jar"/> <fileset dir="./build" includes="**/AllTests.*"/> </batchtest> </junit> </target> <target name="compile"> <javac srcdir="./src/JunitSuiteProject" destdir="./build" includeantruntime="true"> <classpath location="C:\Program Files\Java\apache-ant-1.9.2\lib\selenium-server-standalone-2.35.0.jar" /> </javac> </target> <target name="jar"> <jar destfile="./build/jar/JunitSuite.jar" basedir="./build"> </jar> </target> </project> ************************************************************** package JunitSuiteProject; import junit.framework.TestSuite; import junit.framework.Test; import org.junit.runners.Suite; import org.junit.runner.RunWith; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({JunitTest1.class}) public class AllTests extends TestSuite{ public static Test Suite(){ TestSuite g = new TestSuite(); g.addTest(new JunitTest1("testprintTest")); return g; } public static void main(String[]args){ junit.textui.TestRunner.run(Suite()); } } |
当我在Junit中指定Jars的位置时,有没有人能让我知道这里的问题为什么我得到ClassNotFoundException当我触发Ant文件时出错。
1 2 3 4 5 6 7 8 9 | The output says: [junit] Running AllTests [junit] Testsuite: AllTests [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] AllTests [junit] java.lang.ClassNotFoundException: AllTests |
使用的junit是3.8版本,它作为junit测试执行正常但从build.xml文件启动时出错。
JUnit 4的当前发行版包括旧命名空间的副本,以便于迁移; 但是你应该避免使用JUnit3表单进行新测试,并尽可能将旧测试转换为JUnit 4。
在JUnit 4中,两个包都包含在库jar中以进行迁移,但是您应该使用org.junit.Test来获取新代码,并且这些测试不需要扩展TestCase。
您可以看到Junit4测试用例的基本示例。