Java Test Tools use (1)--junit

Source: Internet
Author: User

Before testing, you need to import JUnit's two packages, respectively

junit:4.12;hamcrest-core:1.1

1. Basic Test Label

@Test, @Before, @After

2. Group Testing

Sometimes multiple test files, if one goes to execute is certainly a waste of time, then how to do it?

If there are Firtest.java,sectest.java now, there are multiple methods in each test class, how do you want to test this file together?

Create a new Java test file named Grouptest, and then write the code

@RunWith (Suite.  Class) @Suite. suiteclasses ({        firtest. class ,        Sectest. class })publicclass  grouptest {        //  keep empty  }

Then right-click to run the class.

3. Ignoring a test method

@Ignore

4, require a method to run the maximum time

@Test (timeout=1000)//unit is MS

  

  

Can be found that although the super-times wrong, but still down the implementation of

You can do this if you want to limit all the methods in this test class (note that this 4.10 version is not available)

  

  

Java Test Tools use (1)--junit

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.