-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10774 from Harsh4902/main
Add a small documentation for ApprovalTests
- Loading branch information
Showing
3 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/resources/generator/server/javatool/approvaltesting/approval-testing.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Approval based testing with ApprovalTests | ||
|
||
Instead of writing individual assertions, ApprovalTests focuses on verifying the overall output. This is particularly useful when testing complex objects, files, or outputs where writing assertions would be tedious. | ||
|
||
Here is the example of approval-based tests from [ApprovalTests.java User Guide](https://github.com/approvals/ApprovalTests.Java/blob/master/README.md) | ||
|
||
```java | ||
import java.util.Arrays; | ||
import org.approvaltests.Approvals; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class SampleArrayTest { | ||
|
||
@Test | ||
public void testList() { | ||
String[] names = { "Llewellyn", "James", "Dan", "Jason", "Katrina" }; | ||
Arrays.sort(names); | ||
Approvals.verifyAll("", names); | ||
} | ||
} | ||
|
||
``` | ||
|
||
This will a File `SampleArrayTest.testList.received.txt` | ||
|
||
Simply rename this to `SampleTest.testList.approved.txt` and the test will now pass. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters