JUnit 테스트를 실행하여 예외를 throw하는 메서드를 테스트하려고합니다. 그러나 테스트가 실패하고 실패 이유에 대한 단서가 없습니다. 예외를 throw하는 메서드는 다음과 같습니다. calcultor.setN() ;. 나는이 테스트의 두 가지 버전을 만들었지 만, 통과해야하더라도 두 가지 모두 실패합니다.JUnit 예외 테스트가 실패합니다 (예기치 않게)
@Rule
public ExpectedException exception = ExpectedException.none();
@Test
public void testSetNZero() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("Het aantal CPU's is minder dan 1");
Amdahl calculator = new Amdahl();
calculator.setN(0);
fail("Exception not thrown");
}
@Test (expected = IllegalArgumentException.class)
public void testSetNZero() {
Amdahl calculator = new Amdahl();
calculator.setN(0);
}
암달 클래스 :
public class Amdahl
{
private int N;
public void setN (int n) {
if(n < 1) throw new IllegalArgumentException ("Het aantal CPU's is minder dan 1");
this.N = n;
}
}
당신은 내가이 방법은 어떤 예외를 던질 않는 암달 클래스 – Reimeus
은'Amdahl' 클래스를 게시 할 수 있습니까? '예외 '가 어떻게 선언됩니까? – Simon
을 추가 한 – axtavt