相关疑难解决方法(0)

是否可以在JUnit中为每个测试用例使用不同的@Before @After?

我是新手Java & JUnit,遇到了不同的灯具.我在网上搜索了很多,但我找不到答案.

是否可以@Before @After针对不同的测试用例使用不同的JUnit?例如:我有以下TC,那么可以使用不同@Before的测试和不同@Before的test1

 import static org.junit.Assert.assertEquals;

 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;

 public class testJUnit {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    System.out.println("Before Class");
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
    System.out.println("Tear Down After Class");
}

@Before
public void setUp() throws Exception {
    System.out.println("Setup");
}

@After
public void tearDown() throws Exception {
    System.out.println("Tear Down");
}

@Test …
Run Code Online (Sandbox Code Playgroud)

java eclipse junit unit-testing

9
推荐指数
2
解决办法
6214
查看次数

标签 统计

eclipse ×1

java ×1

junit ×1

unit-testing ×1