Skip to content

Instantly share code, notes, and snippets.

@weikangchia
Last active April 17, 2022 13:39
Show Gist options
  • Save weikangchia/52536f25f55f04de4b5ffcdc63f9ecad to your computer and use it in GitHub Desktop.
Save weikangchia/52536f25f55f04de4b5ffcdc63f9ecad to your computer and use it in GitHub Desktop.
import org.junit.jupiter.api.Test;
import java.time.Duration;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTimeout;
class JUnit5Test {
@Test
void shouldThrowRuntimeException() {
assertThrows(RuntimeException.class, () -> {
throw new RuntimeException("Exception met");
});
}
@Test
void shouldTimeoutAfter1Milliseconds() {
assertTimeout(Duration.ofMillis(1L), () -> Thread.sleep(500));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment