English 中文(简体)
第4组
原标题:TestSuite Setup in jUnit 4

我已设法查明如何在四分五栏中进行测试,但我确实错过了在一次测试中总结诉讼的可能性。

关于如何在四分五栏为一套测试案例而安装的“BeforeClass/@AfterClass”的想法?

页: 1

@RunWith(Suite.class)
@Suite.SuiteClasses({Test1.class, Test2.class})
public class MyTestSuite {
    @BeforeClass public static void setUpClass() {
        // Common initialization done once for Test1 + Test2
    }
    @AfterClass public static void tearDownClass() {
        // Common cleanup for all tests
    }
}

不幸的是,上述代码零碎不成不变。 @BeforeClass, only work on a per-test-class basis.

最佳回答

这里是我拥有的,它只是罚款。

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ TestSuite1.class, TestSuite2.class })
public class CompleteTestSuite {

    @BeforeClass 
    public static void setUpClass() {      
        System.out.println("Master setup");

    }

    @AfterClass public static void tearDownClass() { 
        System.out.println("Master tearDown");
    }

}

这里是我的试样1(测试套2)。

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(value = Suite.class)
@SuiteClasses(value = { TestCase1.class })
public class TestSuite1 {}

这里是我的考验。 创建测试案例1和测试案例2。

import static org.junit.Assert.assertEquals;

import org.junit.BeforeClass;
import org.junit.Test;

public class TestCase1 {

    @BeforeClass 
    public static void setUpClass() {      
        System.out.println("TestCase1 setup");
    }

    @Test
    public void test1() {
        assertEquals(2 , 2);
    }
}    

you should have 5 classes completesuite suite1 suite2 test1 test2

并且确保你在你们的建设道路上有共同点。 我们应该这样做!

这里是产出

Master setup
TestCase1 setup
Master tearDown
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签