为什么我的@BeforeClass方法运行? [英] Why isn't my @BeforeClass method running?

查看:877
本文介绍了为什么我的@BeforeClass方法运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

  @BeforeClass
    公共静态无效setUpOnce()抛出InterruptedException的{
        失败(LOL);
    }

这要么是@Before,@After,@Test或@AfterClass方法的各种其它方法。

在启动时,因为它似乎它应该测试不会失败。有人可以帮我吗?

我的JUnit 4.5

该方法是在没有设置一个即时调用(),它被注释为@Before。
类DEF是:

 公共类myTests扩展TestCase的{


解决方案

不扩展TestCase,并在同一时间使用注释!

如果你需要创建一个测试套件与注释,使用RunWith注释,如:

  @RunWith(Suite.class)
@ Suite.SuiteClasses({MyTests.class,OtherTest.class})
公共类AllTests中{
    //空
}
公共类MyTests {//无法在这里延伸
    @BeforeClass
    公共静态无效setUpOnce()抛出InterruptedException的{
        ...
    @测试
    ...

(按约定:用大写字母类名)

I have the following code:

    @BeforeClass
    public static void setUpOnce() throws InterruptedException {
        fail("LOL");
    }

And various other methods that are either @Before, @After, @Test or @AfterClass methods.

The test doesn't fail on start up as it seems it should. Can someone help me please?

I have JUnit 4.5

The method is failing in an immediate call to setUp() which is annotated as @before. Class def is :

public class myTests extends TestCase {

解决方案

do NOT extend TestCase AND use annotations at the same time!
If you need to create a test suite with annotations, use the RunWith annotation like:

@RunWith(Suite.class)
@Suite.SuiteClasses({ MyTests.class, OtherTest.class })
public class AllTests {
    // empty
}


public class MyTests {  // no extends here
    @BeforeClass
    public static void setUpOnce() throws InterruptedException {
        ...
    @Test
    ...

(by convention: class names with uppercase letter)

这篇关于为什么我的@BeforeClass方法运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆