flowchart
WriteTest["Write a test with an empty expectation"] --> Fail
Fail --> reporter["Open Reporter of original test source code vs. modified source code(Diff Tool)"]
reporter --> ApproveNewSource["Approve the new source code"]
ApproveNewSource --> Pass
style Fail fill:#f00
style Pass fill:#0f0
Inline approvals feel a lot like regular approvals except for the expected result is stored in the source in the test method, like a regular JUnit test.
Write the test with no expectation
@Test
public void testInlineApprovals()
{
var expected = """
""";
Approvals.verify(getGreeting(), new Options().inline(expected));
}
When you run this, a diff program will pop up. But instead of showing just the approved and received, it will show you the original source code and the source code needed to approve the received result. Here is an example:
You can approve this the same as normal: by moving the received from the left to the right.
The resulting test will have the approved text at the top of the test.
@Test
public void testInlineApprovals()
{
var expected = """
Hello world!
Welcome to inline approvals!
""";
Approvals.verify(getGreeting(), new Options().inline(expected));
}