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