junit will mark the test as being in an “error state” if an exception is thrown from this method. For most cases, this is essentially the same as rejecting a test (in the sense that a test that completed in an error state did not succeed). Many test authors do not like the problems (or code evasion) associated with handling checked exceptions.
, , :
public class SomeTest
SomeObject so;
@Before
public void setUp() {
so = new SomeObject();
}
@Test
public void TestSomeFlow() {
try {
so.init();
} catch (InitExceptionIDontCareAbout e) {
fail ("init failed");
}
try {
so.doSomething();
} catch (SomeOtherExceptionIDontCareAbout e) {
fail ("doSomething failed");
}
assertTrue ("doSomething didn't work", so.isSomethingDone());
}
}
, :
public class SomeTest
SomeObject so;
@Before
public void setUp() {
so = new SomeObject();
}
@Test
public void TestSomeFlow() throws Exception {
so.init();
so.doSomething();
assertTrue ("doSomething didn't work", so.isSomethingDone());
}
}