JUnit4 , ExpectedException, @Rule,
import org.junit.rules.ExpectedException;
import org.junit.Rule;
import org.junit.Test;
public class MyTestClass {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void aTestThatSucceedsOnlyIfRuntimeExceptionIsThrown() {
thrown.expect(RuntimeException.class);
}
}
, @Test(expected=RuntimeException.class), : , . , , ( ), , .