Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. # Diferences
  2.  
  3. ## JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage
  4. - **JUnit Platform** serves as a foundation for launching testing frameworks on the JVM.
  5. - **JUnit Jupiter** is the combination of the new programming model and extension model for writing tests and extensions in JUnit 5.
  6. - **JUnit Vintage** provides a TestEngine for running JUnit 3 and JUnit 4 based tests on the platform.
  7.  
  8. ## Annotations
  9. JUnit 5 comes with important changes within its annotations. The most important one is that we can no longer use `@Test` annotation for specifying expectations.
  10.  
  11. ### `expected` attribute can be replaced with `assertThrows`
  12.  
  13. ```java
  14. @Test(expected = Exception.class)
  15. public void shouldRaiseAnException() throws Exception {
  16. // ...
  17. }
  18. ```
  19.  
  20. becomes,
  21.  
  22. ```java
  23. public void shouldRaiseAnException() throws Exception {
  24. Assertions.assertThrows(Exception.class, () -> {
  25. //...
  26. });
  27. }
  28. ```
  29.  
  30. ### `timeout` attribute can be replaced with `assertTimeout`
  31.  
  32. ```java
  33. @Test(timeout = 1)
  34. public void shouldFailBecauseTimeout() throws InterruptedException {
  35. Thread.sleep(10);
  36. }
  37. ```
  38.  
  39. becomes
  40.  
  41. ```java
  42. @Test
  43. public void shouldFailBecauseTimeout() throws InterruptedException {
  44. Assertions.assertTimeout(Duration.ofMillis(1), () -> Thread.sleep(10));
  45. }
  46. ```
  47.  
  48.  
  49. ## import location
  50. | JUnit4 | JUnit5 |
  51. |---|---|
  52. | `org.junit.Test` | `org.junit.jupiter.api.Test` |
  53. | `org.junit.Before` | `org.junit.jupiter.api.BeforeEach` |
  54. | `org.junit.After` | `org.junit.jupiter.api.AfterEach` |
  55. | `org.junit.BeforeClass` | `org.junit.jupiter.api.BeforeAll` |
  56. | `org.junit.AfterClass` | `org.junit.jupiter.api.AfterAll` |
  57. | `org.junit.Ignore` | `org.junit.jupiter.api.Disabled` |
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement