selenium – org. junit. Test and JUnit framework. Differences between test packages

<project name="JunitSuite" basedir="." default="clean">
<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());
        }
    }

When I specify the location of jars in JUnit, can anyone let me know why I get classnotfoundexception? There is an error when I trigger the ant file

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,Time elapsed: 0 sec
    [junit] Null Test:  Caused an ERROR
    [junit] AllTests
    [junit] java.lang.ClassNotFoundException: AllTests

JUnit used is version 3.8, which performs normally as a JUnit test, but from build Error starting XML file

Solution

junit. framework. The test package is an old namespace used by JUnit V3 for older versions of Java that do not support annotations

org. junit. Test is a new namespace used by JUnit V4, which requires Java v1 5 or later If possible, use JUnit 4 and the latest Java, because the new annotations are very superior The current release of JUnit 4 includes a copy of the old namespace to facilitate migration; However, you should avoid using JUnit 3 for new tests and convert them to JUnit 4 tests

In JUnit 4, both packages are included in the library for migration, but you should use org junit. Test to get new code without extending testcase

You can see a basic example of junit4 test case

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>