Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 {
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
229 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...