Reputation: 111
I have a problem with Idea 14 and JUnit. I can't run @BeforeClass and @AfterClass methods in proper order (before all test and after all test). Every time order is different. I tried to reinstall IDEA, delete all settings but nothing works. Please help. This is example of my test code:
package com.rent.test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.junit.Assert.*;
import org.junit.Test;
public class testnewTest {
static int num;
static int num1;
@BeforeClass
public static void OnceExecutedBeforeAll() {
System.out.println("@BeforeClass: onceExecutedBeforeAll");
num = 15;
num1 = 16;
}
@AfterClass
public static void after() throws Exception {
System.out.println("End");
}
@Test
public void testLogin() throws Exception {
System.out.println("test");
assertEquals(15, num);
}
@Test
public void testGetOrdersDate() throws Exception {
System.out.println("test2");
assertEquals(16, num1);
}
}
This is output:
test2
@BeforeClass: onceExecutedBeforeAll
test
End
Upvotes: 1
Views: 449
Reputation: 106460
What you're likely observing is the fact that the output is not always going to be synchronous in the terminal. The test themselves are running in the correct sequence.
If they weren't, then you would have failures in test2
given that it would have appeared that your @BeforeClass
method fired afterwards.
Upvotes: 3