JUnit software testing for maven under eclipse

Source: Internet
Author: User

One, Maven project management and build automation tool, more and more developers use it to manage the project jar. This article describes how Eclipse installation, the configuration and use Maven. (This article draws in the experience of Wu Di students, but most of the steps is different from he writing, I have pers Onally been completed.)

Second, test environment:win7 Ultimate + adt-eclipse

Third, first you are having to make sure, which has configured the JAVA environment, learning software must believe it won't be Unfamiliar, the Internet can easily search for an installation article won't repeat them here.

Iv. MAVEN Environment Configuration:go to official website download Mawen files,extract to the root directory of your expectations, and th En configure the environment variables.

Updates about the configuration:

maven_home:d:\apache-maven-3.3.1 (I chose to unpack on the D drive)


path:%maven%; (Plus an additional note on the back of PATH;)

V. Open the Console,input mvn-v


The following interface proved successful installation.

Vi. use of "compile,test,package" to build the project

1.First, input

$MVN archettype:generate

Then it would download the file of maven.

After a while,then it reminds your enter GroupID and some data, you can fill in according to your own situation.i would give a example.




... push enter to continue.

Last it says Bilud Success,and in your in the directory of C:/user/yourname you has created your own Proje Ct.

| '--Java
| '--com
| '--MyCompany
| '--app
| '--App.java


$CD my-app-SIMPLE$MVN compile

Push Enter


$MVN Test


4.package, Input:



Your Maven project So far have been built.

Vii. Eclipse Maven Plugin installed (if you already had,then jumped this step)

You can goto the following blog and get a eclipse maven plugin.                There,and download the file with my Baidu cloud share. Http://pan.baidu.com/s/1kTvdteJ

Eight, import the project you build.

Open you eclipse,and choose import->others->maven->existing Maven Projects.

Then choose Properties->java Build Path->add library->junit.

X. Write your App.java and Apptest.java


 PackageCom.mycompany.app;/*** Hello world! **/ Public classapp{ PublicString Sayapp () {return"Hello wanghui_3012218097!"; }               Public Static voidMain (string[] args) {app app=NewApp (); System.out.println ("Hello wanghui_3012218097!" ); }}


 PackageCom.mycompany.app;Importjunit.framework.Test;Importjunit.framework.TestCase;ImportJunit.framework.TestSuite;/*** Unit test for simple App.*/ Public classapptestextendstestcase{/*** Create The test case * *@paramtestname name of the test case*/     Publicapptest (String testname) {Super(testname); }     /**     * @returnThe suite of tests being tested*/     Public StaticTest Suite () {return NewTestSuite (apptest.class ); }     /*** rigourous Test:-)*/     Public voidtestApp () {app app=Newcom.mycompany.app.App (); Assertequals ("Hello wanghui_3012218097!", App.sayapp ()); }}

In the END

Choose Run As->junit Test

And the result in there:

If your work has no problem, then you had did it.

Xi. Summary

It's a good the-to-do the JUnit Test,and under the maven we had a better enviroment to manager a team.so and professional to Ol'll make you effective.

JUnit software testing for maven under eclipse

Related Article

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.