JUnit Advanced Chapter (parametric, packaged test)-instance code

Source: Internet
Author: User

Project Catalog:

Parametric testing, Squaretest.java:

1 Import Staticorg.junit.assert.*;2 3 Importjava.util.Arrays;4 Importjava.util.Collection;5 6 ImportOrg.junit.Before;7 Importorg.junit.Test;8 ImportOrg.junit.runner.RunWith;9 Importorg.junit.runners.Parameterized;Ten Importorg.junit.runners.Parameterized.Parameters; One  A@RunWith (parameterized.class) -  Public classSquaretest { -     Private StaticCalculator Calculator =NewCalculator (); the     Private intparam; -     Private intresult; -      -      + @Parameters -      Public StaticCollection data () { +         returnArrays.aslist (Newobject[][]{ A{2,4}, at{0,0}, -{ -3,9}, -         }); -     } -      -     //constructor to initialize the variable in      PublicSquaretest (intParamintresult) { -          This. param =param; to          This. result =result; +     } -      the @Test *      Public voidSquare () { $ calculator.square (param);Panax Notoginseng assertequals (Result,calculator.getresult ()); -     } the      +}
View Code

Package Test, Allcalculatortests.java:

1 ImportOrg.junit.runner.RunWith;2 ImportOrg.junit.runners.Suite;3 4@RunWith (Suite.class)5 @Suite. suiteclasses ({6Calculatortest.class,7Squaretest.class8 })9  Public classallcalculatortests {Ten  One}
View Code

Results of executing Allcalculatortests.java

JUnit Advanced Chapter (parametric, packaged test)-instance code

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.