|
本帖最后由 六月长青 于 2013-10-15 15:42 编辑
使用Junit4进行参数化后测试。运行结果如下,每运行一个test,都会调用setup和tear:- setUpBeforeClass
- constructed
- setUp
- test1:111
- tear
- constructed
- setUp
- test2:111
- tear
- constructed
- setUp
- test1:222
- tear
- constructed
- setUp
- test2:222
- tear
- tearDownAfterClass
复制代码 但是想要这样的结果,即每执行一轮参数时,所有test前后运行一次指定参数。要如何实现?setUpBeforeClass中不能获取参数化数据。所以不能放到这里。- setUpBeforeClass
- setUptest
- test1:111111
- test2:111111
- teartest
- setUptest
- test1:222222222
- test2:222222222
- teartest
- tearDownAfterClass
复制代码- @RunWith(Parameterized.class)
- public class test {
- private int str1;
-
- @Parameters
- public static Collection prepareData(){
- Object [][] object = {{111111},{222222222}};
- System.out.println("prepareData");
- return Arrays.asList(object);
- }
-
- public test(int s1){
- this.str1=s1;
- System.out.println("constructed");
-
- }
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- System.out.println("setUpBeforeClass");
- }
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- System.out.println("tearDownAfterClass");
- }
- @Before
- public void setUp() throws Exception {
- System.out.println("setUp");
- }
- @After
- public void tearDown() throws Exception {
- System.out.println("tear");
- }
- @Test
- public void test1() {
- System.out.println(" test1:"+str1);
-
- }
- @Test
- public void test2() {
- System.out.println(" test2:"+str1);
-
- }
- }
复制代码 |
|