Automatic building of Android projects using Jenkins (4)

Source: Internet
Author: User

Adding unit Tests

Many of the Android unit tests are done using instrumentation, which is about trying junit, why use JUnit? Because using instrumentation requires you to package the APK installation and then test it, you need to test another project with one project. The unit test I want to do now is to do some test validation before packaging, so I need junit. As for unit tests using instrumentation, we'll go into the details later.

The structure of the MAVEN default source src directory and test code testing directory is

Src/main/java

Test/java

The following directory structure is found in actual use Maven can also use

src/

test/

This should be because the project source code and the test code need to be compiled separately, in target is also placed separately. If you run in Maven directly with Eclipse's Android project structure (which you need to put under SRC in eclipse), there will be an error similar to the package junit.framework does not exist. So you need to execute the command before the build to move the test directory outside of SRC.

Unit test code, in the new JUnit, the test method already does not need to start with testing, just add @Test.

Package Com.example.demo;
Import Nmg.util.publicdata;import junit.framework.assert;import Org.junit.test;import Org.junit.Ignore;import Org.junit.runner.runwith;import org.junit.runners.JUnit4; @RunWith (junit4.class) public class Testurl { @Test Public void Prodapi () { String equals = Publicdata.http_url; Assert.assertequals ("http://prod.xxx.com", equals); } @Test public void Devapi () { String equals = Publicdata.http_url; Assert.assertequals ("http://dev.xxx.com", equals); } /* @Test @Ignore public void thisisignored () { } */ }

Using MAVEN to compile the package, the class that starts with test in the test directory is treated as a test class, and if the class name using Testsuite,testsuite starts with test, the class name of TestCase does not need to start with test, avoiding duplication of execution.

Package Com.example.demo; Import Org.junit.runner.RunWith ; Import Org.junit.runners.Suite; @RunWith (Suite.class) @Suite. suiteclasses ({    checkappinfo1.class,    checkappinfo2.class  } ) public class Testgroup {      }  

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.