| Line 134: |
Line 134: |
| | The convention is tu follow the structure shown on the image. | | The convention is tu follow the structure shown on the image. |
| | | | |
| − | === Test example === | + | ===Test example=== |
| | <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| | package com.luv2code.junitdemo; | | package com.luv2code.junitdemo; |
| Line 156: |
Line 156: |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | === Run unit test === | + | ===Run unit test=== |
| | | | |
| − | ==== All tests ==== | + | ====All tests==== |
| | <syntaxhighlight lang="bash"> | | <syntaxhighlight lang="bash"> |
| | mvn test | | mvn test |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | ==== Single test ==== | + | ====Single test==== |
| | <syntaxhighlight lang="bash"> | | <syntaxhighlight lang="bash"> |
| | mvn -Dtest=TestMessageBuilder test | | mvn -Dtest=TestMessageBuilder test |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | | | |
| − | ==== Single test method from one test class ==== | + | ====Single test method from one test class==== |
| | <syntaxhighlight lang="bash"> | | <syntaxhighlight lang="bash"> |
| | mvn -Dtest=TestMessageBuilder#testHelloWorld test | | mvn -Dtest=TestMessageBuilder#testHelloWorld test |
| | </syntaxhighlight> | | </syntaxhighlight> |
| | + | |
| | + | === JUnit Assertions === |
| | + | <br /><syntaxhighlight lang="java"> |
| | + | import static org.junit.jupiter.api.Assertions.*; |
| | + | </syntaxhighlight>org.junit.jupiter.api.Assertions contains JUnit Assertions |
| | + | |
| | + | assertEquals(expected, actual, optional_message) |
| | + | |
| | + | assertNotEquals(unexpected, actual, optional_message) |
| | + | |
| | + | assertNull() |
| | + | |
| | + | assertNotNull() |
| | + | |
| | + | .... |
| | | | |
| | ==Example: Spring Boot with Data JPA and in memory database H2== | | ==Example: Spring Boot with Data JPA and in memory database H2== |