MAVEN Learning---Using MAVEN to run unit tests

Source: Internet
Author: User

To run unit tests from MAVEN, issue this command:

MVN test

This will run the entire unit test in your project.

Case study

Create a two unit test and run it through Maven. See a simple Java test class:

Package Com.yiibai.core;public class App {public static void main (string[] args) {System.out.println (Gethelloworld ());} public static String Gethelloworld () {return ' Hello world ';} public static String GetHelloWorld2 () {return ' Hello World 2 ';}}
Unit Test 1

The unit test is the Gethelloworld () method.

Package Com.yiibai.core;import Junit.framework.assert;import Org.junit.test;public class TestApp1 {@Testpublic void Testprinthelloworld () {assert.assertequals (App.gethelloworld (), "Hello World");}}
Unit Test 2

The unit test is the GetHelloWorld2 () method.

Package Com.yiibai.core;import Junit.framework.assert;import Org.junit.test;public class TestApp2 {@Testpublic void TestPrintHelloWorld2 () {assert.assertequals (App.gethelloworld2 (), "Hello World 2");}}
Run unit Tests

Using MAVEN to run unit tests see the following example.

Example 1
Run the entire unit test (TESTAPP1 and TESTAPP2) and issue the following command:

MVN test

Example 2
In order to run a single test (TESTAPP1), issue this command:

MVN-DTEST=TESTAPP1 test [INFO]---maven-compiler-plugin:3.1:compile (default-compile) @ yiibai-core--[INFO] nothing to Compile-all classes is up to Date[info][info]---maven-resources-plugin:2.6:testresources (default-testresources) @ y Ibai-core---[INFO] Using ' UTF-8 ' encoding to copy filtered resources. [INFO] Skip non existing resourcedirectory C:\worksp\yiibai-core\src\test\resouces[info][info]---  Maven-compiler-plugin:3.1:testcompile (default-testcompile) @ yiibaicore---[INFO] nothing to Compile-all classes is up To Date[info][info]---maven-surefire-plugin:2.12.4:test (default-test) @ yiibai-core---[INFO] Surefire report Directo Ry:c:\worksp\yiibai-core\target\surefire-reports-------------------------------------------------------t E S t S-------------------------------------------------------Running com.yiibai.core.TestApp1Tests run:1, failures:0, errors:0, skipped:0, Time elapsed:0.002 secresults:tests run:1, failures:0, errors:0, Skipped:0[info]------------------------------------------------------------------------[INFO] BUILD Success[info]--------------------- ---------------------------------------------------[INFO] Total time:2.143 s[info] finished at:2015-11-03t20:29:50+ 08:00[info] Final Memory:11m/114m[info]------------------------------------------------------------------------

Example 3
In order to run a single test (TESTAPP2), issue this command:

MVN-DTEST=TESTAPP2 Test
Attention
For more examples of "mvn test", refer to the MAVEN test plugin documentation.


Tags: Maven run unit Test

This site is reproduced in addition to the article, are the original site or compiled
Welcome any form of reprint, but please be sure to indicate the source, respect for the work of others to create excellent examples of the tutorial
Reprint Please specify: Article reprinted from: http://www.yiibai.com/maven/run-unit-test-with-maven.html

MAVEN Learning---Using MAVEN to run unit tests

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.