JUnit command line execution

Source: Internet
Author: User

The Java command-line program executes a main. What if we want to run a test column with a command line? Of course maven can be very convenient to do, the following describes a relatively primitive approach. We're going to use org.junit.runner.JUnitCore here.

1, to be carried out the test class, in order to space, I try to brief

Import Org.junit.test;public class CTest {@Testpublic void Ctest1 () {System.out.println ("Ctest1");}}

2. Write a Main

Import Org.junit.runner.junitcore;import Org.junit.runner.result;import org.junit.runner.notification.Failure; public class Junitrunner {/** * @param args */public static void main (string[] args) {result result = Junitcore.runclasses (Ctest.class); for (Failure failure:result.getFailures ()) {System.out.println (failure.tostring ());} if (result.wassuccessful ()) {System.out.println ("All test columns executed successfully");}}}

3, implementation. The JUnit dependency jar is required for execution, but Eclipse has the JUnit jar. To facilitate execution, I put the dependency jar junit-4.11.jar/

Hamcrest-core-1.3.jar Copy the directory to the Java file.

Compilation: Javac-encoding UTF-8-classpath.;. /junit-4.11.jar;. /hamcrest-core-1.3.jar Ctest.java Junitrunner.java

Execution: Java-classpath.;. /junit-4.11.jar;. /hamcrest-core-1.3.jar Junitrunner

The output is as follows:

Ctest1 all test columns executed successfully

JUnit command line execution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.