JENKINS+ANT+JAVA+JUNIT+SVN Use summary __tomcat

Source: Internet
Author: User
Tags assert mkdir svn

I. Environmental preparedness Jenkins: to the official website Download Jenkins.war Package: http://jenkins-ci.org/installation method has two kinds: the download of the Jenkins.war package under the folder, such as C:\jenkins, and then open the Command Line window to go to the directory, Executes the Java-jar Jenkens.war command, when prompted: "Jenkins is fully up and running" when the start is successful, then enter in the browser window: http://localhost:8080/ You can go to Jenkins's homepage. If you have Tomcat, put the Jenkins.war package under Tomcat's WebApps folder, and start Tomcat automatically when the Jenkins is started, by Http://localhost:8080/jenkins You can visit the home page of Jenkins. Ant:

Download Ant and configure Ant_home, official website: http://ant.apache.org/.

3. Junit:

Download Junit.jar package, no use can refer to: http://blog.csdn.net/lengyuhong/article/details/5815017

4, SVN:

1, with local hard disk when SVN warehouse: http://wenku.baidu.com/view/12b02f6a011ca300a6c39081.html

2, SVN server to build and use: http://www.cnblogs.com/xiaobaihome/tag/SVN/(Recommended This method, there are reasons behind)

second, the project code:

  When the environment is ready, you can start writing code, Unit test cases, and the build.xml files that Ant uses to build, which were mentioned in the previous Ant task JUnit, Junitreport, which is not detailed here:

1, Java code:

Package com.glen.he;

public class Complexcalculation {public
    int division (int A,int b) {return        
        (A/a);        
    }

    public int Multiply (int a,int b) {return        
        (a*b);        
    }
}

Package com.glen.he;

public class Simplecalculation {public
    int Add (int a,int b) {return        
        (a+b);        
    }

    public int subtration (int a,int b) {return
        (a-b);
    }
    
}

2, Unit test code:

Package com.glen.he;

Import com.glen.he.ComplexCalculation;

Import static org.junit.assert.*;

Import Org.junit.Test;


public class Complexcalculationtest {
    
    complexcalculation cc = new Complexcalculation ();
    
    @Test public
    void Divisiontest () {
        
        int c = cc. Division (5);
        
        Assertequals (c);        
    }

    @Test public
    void Multiplytest () {
        
        int c = cc. Multiply (5);
        
        Assertequals (c);        
    }
}

Package com.glen.he;

Import com.glen.he.SimpleCalculation;

Import static org.junit.assert.*;
Import Org.junit.Test;

public class Simplecalculationtest {

    simplecalculation sc = new simplecalculation ();
    
    @Test public
    void Addtest () {
        
        int c = SC. ADD (3, 5);    
        
        Assertequals (8, c);        
    }
    
    @Test public
    void Subtrationtest () {
        
        int c = SC. Subtration (5);    
        
        Assertequals (c);        
    }
}

3, Build.xml

<?xml version= "1.0" encoding= "UTF-8"?> <project name= "Antdemo" "JUnit" default= "." > <!--===================================================================--> <!--variable set--> & lt;! --===================================================================--> <!--source code src path--> <propert Y name= "Src.path" value= "Src/java"/> <!--unit Test code path--> <property name= "Test.path" value= "Src/test"/&gt
    ; <!--compile file class path--> <property name= "Build.path" value= "Build"/> <!--jar package path--> <propert Y name= "Dist.path" value= "dist"/> <!--lib package path--> <property name= "Lib.path" value= "Lib"/> <! --Generate Reports Junit4.xml path--> <property name= "Report.path" value= "Report"/> <!--================== =================================================--> <!--settings Classpath--> <!--====================== =============================================--> <path id= "Compile.path" > <fileset dir= "${lib.path}" > <inclu De name= "**/*.jar"/> </fileset> <pathelement path= "${build.path}"/> </path&     

    Gt <!--initialization--> <target name= "init" > <mkdir dir= "${build.path}"/> <mkdir dir = "${report.path}"/> <mkdir dir= "${dist.path}"/> </target> <!--==================== ===============================================--> <!--Clear History compilation class--> <!--======================== ===========================================--> <target name= "clean" description= "clean" >
    ;d elete dir= "${build.path}"/> <delete dir= "${report.path}"/> <delete "dir=}" ${dist.path </target> <!--===================================================================--> <!--compiling test Trial files, initializing the table of contents--> <!--===================================================================--> <target name= "compile "Depends= init" > <javac srcdir= "${src.path}" destdir= "${build.path}" classpathref= "Compile.path" Includean Truntime= "true"/> <javac srcdir= "${test.path}" destdir= "${build.path}" classpathref= "Compile.path" Includea Ntruntime= "true"/> </target> <!--==================================================== ===============--> <!--execute test Cases--> <!--============================================================= = = = =--> <target name= "JUnit" depends= "compile" > <junit printsummary= "true" fork = "true" > <formatter type= "xml" usefile= "true"/> <classp Ath refid= "Compile.path"/> <batchtest fork= "on" todir= "${report.path}" Haltonfailur
             E= "No" >   <fileset dir= "${build.path}" > <include name= "**/*test.class"/> </fil eset> </batchtest> </junit> </target> ; Target Name= "Junit-report" depends= "JUnit" > <!--generating Unit test report document--> <junitreport todir= "$
            {Report.path} "> <fileset dir=" ${report.path} "> <include name=" Test-*.xml "/> </fileset> <report format= "frames" todir= "${report.path}"/> </j
          unitreport> </target> <target name= "Make-jar" depends= "compile" description= "Make Jar file" > <jar jarfile= "${dist.path}/antdemo.jar" > <fileset dir= "${build.path}" > &l t;! --Remove Test file--> <exclude name= "**/*test.class"/> </fileset> </jar > </target> </project> 

Third, the configuration Jenkins:

  Ps:jenkins can support distributed job operations through Master/slave, which runs in master, the machine where Jenkins resides.

 1, Open Jenkins homepage, a new job, enter the item name, choose to build a free style software project, click "OK"

2, in the source management there, choose Subversion, after the repository URL, enter your SVN address.

Ps:repository URL uses local disk as warehouse This method later I tried on other machines, I found the error is always: svn:E180001:Unable to open a ra_local session to URL. Temporarily did not find a solution, if you also encounter this problem, you can build SVN server to manage the source code, I tried, very good.

3. There are two ways to build there:

I, select Execute Windows Batch command, enter the following commands in the input box (this is the method I chose here):

Set Path=c:\ant_home\apache-ant-1.7.0\bin;path adds ANT's installation directory to path

Ant JUnit executes the JUnit task

II, method I more trouble, if we set the Ant_home, you can choose Invoke Ant, and then in the targets to specify the task name in our build.xml.

4, click Save, then choose to build immediately, execution results:

Resources:

Http://hi.baidu.com/janice515/item/3272fe9b99eb4cc8b6253101

http://blog.csdn.net/lengyuhong/article/details/5828770

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.