I am new to jUnit, running jUnit testing with @BeforeClass
and @Test
methods. The problem is my @BeforeClass
method is called not once (like it's supposed to) but every time before @Test
method. Same thing happens with @AfterClass
- it runs after each @Test
method. Here's the code:
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.AfterClass;
import java.util.*;
public class MatrixTest {
@BeforeClass
public static void testAdd() {
System.out.println("Before class");
}
@Test
public void testValueSet() {
System.out.println("Hello 1");
}
@Test
public void testMultiply() {
System.out.println("Hello 2");
}
@Test
public void testGetDiagonalSum() {
System.out.println("Hello 3");
}
Output:
Before class
Hello 3
Before class
Hello 2
Before class
Hello 1
Any help would be greatly appreciated. Thanks in advance!
There is no issue here. Make sure you are executing by running as JUnit test.
Update:
There is an open bug for Bluej regarding this issue.
Refer to BLUEJ-437 for more details
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.