zoukankan      html  css  js  c++  java
  • Eclipse下对MAVEN进行junit软件测试

    一、Maven project management and build automation tool, more and more developers use it to manage the project jar. This article describes how Eclipse installation, configuration and use Maven.(This article draws on the experience of Wu Di students, but most of the steps are different from his writing, I have personally been completed.)

    二、test environment:win7 Ultimate + ADT-Eclipse

    三、First you have to make sure that you have configured the JAVA environment, learning software must believe it will not be unfamiliar, the Internet can easily search for an installation article will not repeat them here.

    四、MAVEN environment configuration:go to 官网 download mawen files,extract to the root directory of your expectations, and then configure the environment variables.

      Updates about the configuration:

      MAVEN_HOME: D:apache-maven-3.3.1(I chose to unpack in the D drive)

      MAVEN: %MAVEN_HOME%in

      PATH:%MAVEN%;(Plus an additional note in the back of PATH;)

    五、Open the console,input mvn -v

      

      The following interface proved successful installation.

    六、Use "compile,test,package" to build the project

      1.First ,input

    $mvn archettype:generate

    Then it will download the file of maven.

    After a while,Then it reminds you enter groupID and some data, you can fill in according to your own situation.i will give a example.

      groupId: com.company.app

      artifactId:my-app-simple

      version:1.0

      ...push enter to continue.

      last it says bilud success,and in your in the directory of C:/user/yourname you have created your own project.

      my-app-simple
      |-- pom.xml
        `-- src
        |-- main
        |   `-- java
        |       `-- com
        |           `-- mycompany
        |               `-- app
        |                   `-- App.java
        `-- test
           `-- java
              `-- com
                         `-- mycompany
                            `-- app
                                `-- AppTest.java

      2.input 

    $cd my-app-simple
    $mvn compile

      push Enter

      3.test,input:

    $mvn test

      

      4.package ,input:

      

    $mvn package 

      Still show BUILD SUCCESS.

      Your maven project so far has been built.

    七、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 you download the file with my baidu cloud share.                http://pan.baidu.com/s/1kTvdteJ

    八、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.

    十、write your app.java and apptest.java

    app.java:

    package com.mycompany.app;
     
    /**
     * Hello world!
     *
     */
    public class App
    {
        public String sayApp() {
            return "Hello WangHui_3012218097!";
        }
         
         
        public static void main( String[] args )
        {
            App app = new App();
            System.out.println( "Hello WangHui_3012218097!" );
        }
    }

    apptest.java

    package com.mycompany.app;
     
    import junit.framework.Test;
    import junit.framework.TestCase;
    import junit.framework.TestSuite;
     
    /**
     * Unit test for simple App.
     */
    public class AppTest
        extends TestCase
    {
        /**
         * Create the test case
         *
         * @param testName name of the test case
         */
        public AppTest( String testName )
        {
            super( testName );
        }
     
        /**
         * @return the suite of tests being tested
         */
        public static Test suite()
        {
            return new TestSuite( AppTest.class );
        }
     
        /**
         * Rigourous Test :-)
         */
        public void testApp()
        {
             
            App app = new com.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 have no problem ,then you have did it.

    十一、Summary

      it's a good way to do the junit test,and under the maven we have a better enviroment to manager a team.so ,professional tool will make you effective.

  • 相关阅读:
    【Unity Shader 】CG语法
    编译boost到各个系统平台 mac,iOS,linux,android,wind
    c pvr转存pvr.ccz格式 (转 http://www.cnblogs.com/howeho/p/3586379.html)
    mac Nginx + FastCgi + Spawn-fcgi + c++
    得到指定占用宽度的字体 。(英文占用一个位,中文占用两个位,英文大写占用两个位)
    cocos2d 文件系统使用文件内存映射性能对比
    关于PUPBLD.SQL
    ora-01033:ORACLE initialization or shutdown in progress解决方法
    linux下如何查看命令的绝对路径
    【测试工具】http协议调试利器fiddler使用教程
  • 原文地址:https://www.cnblogs.com/logicvay2010/p/4461089.html
Copyright © 2011-2022 走看看