Pour le lancer, se placer dans le répertoire d'installation et lancer :
java -jar fakeSMTP-2.0.jarLe port d'écoute est configurable (25 par défaut).
java -jar fakeSMTP-2.0.jarLe port d'écoute est configurable (25 par défaut).
#!/bin/bash # FilePaths to testing files generated by clean install testsFile=./target/jacoco-tests.exec run_clean_install () { echo "Running Maven clean install before push" mvn clean install if [ $? -ne 0 ]; then "Error while testing the code, cleaning project" rm "$testsFile" exit 1 fi } if [ ! -f "$testsFile" ]; then echo "File $testsFile not found!" run_clean_install else epochTwentyMinutes=1200 currentEpoch=`/bin/date +%s` testsFileEpoch=`/bin/date -r "$testsFile" +%s` timePassedTestsFileEpoch=`expr $currentEpoch - $testsFileEpoch` if test "$timePassedTestsFileEpoch" -gt "$epochTwentyMinutes"; then echo "Obsoletes tests" run_clean_install fi fi rm "$testsFile" echo "Pre-push hook passed"
@Test(expected = 'MyException.class')Pour Junit 4
@Rule public ExpectedException expectedEx = ExpectedException.none(); @Test public void shouldThrowRuntimeExceptionWhenEmployeeIDisNull() throws Exception { expectedEx.expect(RuntimeException.class); expectedEx.expectMessage("Employee ID is null"); // do something that should throw the exception... }Ou encore tester directement l'exception remontée.
@Test public void shouldThrowMyExceptionWhenMyMockedServiceThrow() throws Exception { MyException myException = Mockito.mock(MyException.class); Mockito.when(myMockedService.myMockMethod()).thenThrow(myException); expectedEx.expect(Is.is(myException)); myInjectedMockService.myInjectedMockMethod(); }
@Test public void shouldThrowMyExceptionWhenMyMockedServiceThrow() throws Exception { MyException myException = Mockito.mock(MyException.class); Mockito.when(myMockedService.myMockMethod()).thenThrow(myException); MyException thrownException = assertThrows(MyException.class, () -> myInjectedMockService.myInjectedMockMethod()); assertEquals(myException, thrownException); verify(myOtherService, times(0)).otherMethod(); }