21

While using JMockit I want to throw an exception upon a constructor invocation like this:

new Expectations(){
        {
           new FirefoxDriver();//Want to throw IllegalStateException here but how?
        }
};
4

2 に答える 2

27

result記録された期待値の結果を指定するには、それをフィールドに割り当てます (返す値またはスローする例外のいずれか) 。

new Expectations() {{
    someMockedMethodOrConstructorInvocation(...); result = new IllegalStateException();
}};
于 2015-03-11T17:11:28.800 に答える