Hello guys I was wondering if this way of testing my exception is ok, i have this exception i need to throw in the second test annotation, im receiving as result a red evil bar, and a succeed and a failure, as you can guess the failure is my concern, i have a fail(); there but the reason is because i read thats the way to test the exception and now im confused.
Also i have to say im willin get the green bar because im expecting the exception, but i dont know if failure is the right way to see the answer of the expected exception.
Also if you had any advice, I would appreciate it
@Before
public void setUp() throws Exception {
LogPack.logPacConfig(Constants.LOGGING_FILE);
gtfri = "+RESP:GTFRI,380502,869606020101881,INCOFER-gv65,,10,1,1,0.0,0,888.1,-84.194560,9.955602,20170220074514,,,,,,0.0,,,,100,210100,,,,20170220074517,40A2$";
weirdProtocol = "+RESP:GRI,380502,869606020101881,INCOFER-gv65,,10,1,1,0.0,0,888.1,-84.194560,9.955602,20170220074514,,,,,,0.0,,,,100,210100,,,,20170220074517,40A2$";
factory = new LocomotiveFactory();
}
@Test
public void GTFRICreationTester_shouldPass() throws TramaConProtolocoloDesconocido {
assertTrue(factory.createLocomotive(gtfri, false, new Date()) instanceof LocomotiveGTFRI);
}
@Test(expected = TramaConProtolocoloDesconocido.class)
public void GTFRICreationTester_shouldFail() {
try {
factory.createLocomotive(weirdProtocol, false, new Date());
fail("Expected an TramaConProtolocoloDesconocido");
} catch (TramaConProtolocoloDesconocido e) {
//assertSame("exception thrown as expected", "no se conoce el protocolo dado para la creacion de este factory", e.getMessage());;
}
}
See Question&Answers more detail:
os