Skip to content

Instantly share code, notes, and snippets.

@jieniu
Last active January 10, 2019 07:49
Show Gist options
  • Save jieniu/13bab0dcff1b442ea270d2c095849899 to your computer and use it in GitHub Desktop.
Save jieniu/13bab0dcff1b442ea270d2c095849899 to your computer and use it in GitHub Desktop.
java assert exception unitest
import static org.junit.jupiter.api.Assertions.assertThrows;
@Test
public void testUsernameIsNull() {
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
User user = new User();
user.setName(null);
});
Assert.assertEquals("expected message", exception.getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment