3 ms·
With Junit, just write @Test(expected = FooBarException.class) void testFooBarException() { thisShouldThrowFooBarException() }
by rdeboo 13y ago
With Junit, just write
@Test(expected = FooBarException.class)
void testFooBarException() {
thisShouldThrowFooBarException()
}
- jaredmcateer 13y agoPHPUnit has this in the comment annotations /** * Tests that thisShouldThrowFooBarException throws FooBarException * * @expectedException FooBarException */ public function testFooBarException() { thisShouldThrowFooBarException(); } but I much prefer /** * Tests that thisShouldThrowFooBarException throws FooBarException */ public function testFooBarException() { $this->setExpectedException('FooBarException'); thisShouldThrowFooBarException(); } Much more explicit and you're less likely to miss it when trying to grok someone else's unittest.