Skip to content

Commit

Permalink
Merge pull request #10774 from Harsh4902/main
Browse files Browse the repository at this point in the history
Add a small documentation for ApprovalTests
  • Loading branch information
murdos authored Sep 12, 2024
2 parents b70291f + 8cdc9c5 commit a868aea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public JHipsterModule build(JHipsterModuleProperties properties) {

//@formatter:off
return moduleBuilder(properties)
.documentation(documentationTitle("Approval Testing"),from("server/javatool/approvaltesting/approval-testing.md"))
.javaDependencies()
.addTestDependency(groupId("com.approvaltests"), artifactId("approvaltests"), versionSlug("approvaltests"))
.and()
Expand Down
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.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ void shouldBuildApprovalTestsModule() {
JHipsterModule module = factory.build(properties);

assertThatModuleWithFiles(module, pomFile())
.hasFiles("documentation/approval-testing.md")
.hasFile("pom.xml")
.containing(
"""
Expand Down

0 comments on commit a868aea

Please sign in to comment.