JUnit unit tests in Android studio and Eclipse

Source: Internet
Author: User

Reprint please indicate source:http://blog.csdn.net/nmyangmo/article/details/51179106



Some time ago someone asked me about the unit test, I would like to summarize to do the following log:

Since I was in touch with Eclipse earlier, let me start with the JUnit configuration in Eclipse. First we build an empty project and add a test class Junittest.java


Second step: Import the JUnit library, project name---> Right-->build Path--->add Libraries ...



Step Three: Click Add Libraries ... After selecting JUnit, select default JUnit 4. Complete




Fourth step: Junittest.java the test class, and right-click on a new JUnit test case




Configure the relevant parameters, as shown in



Select the method you want to test, click Finish


Classes to be tested and corresponding test classes




Fifth step: Test. Method Name--right---run as-->juint test to debug




Choose Eclipse or Eclipse ADT with JUnit for testing




Debug results:








These are the JUnit unit tests in Eclipse, where unit tests are integrated by default and do not require any configuration, just, under the Androidtest folder, build a test class to inherit

Instrumentationtestcase class is good It's good to put the required method into the test. 


First step: Build a Test class Testclass.java and inherit instrumentationtestcase






The second step: Add the test method, the format of the test method should be testxxx, Right-click the method name run can be tested





Run results










The meaning of unit testing: I'm not good at this, but at least I don't feel like running the whole project in order to see the results of a certain number of parameters in a method, and then it is more effective to know the implementation of their ideas. Thank you for your appreciation and if you have any questions, please correct them if you have any questions.




Reprint please indicate source: http://blog.csdn.net/nmyangmo/article/details/51179106


JUnit unit tests in Android studio and Eclipse

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.