From 1dee688375c9749e8a25b5903cf56aeeb74d12ba Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 28 Apr 2022 21:11:16 +0000 Subject: [PATCH] d updated markdown snippets --- .../docs/tutorials/GettingStarted.md | 80 ++++++++++++++----- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/approvaltests/docs/tutorials/GettingStarted.md b/approvaltests/docs/tutorials/GettingStarted.md index 94044a06..93b1411c 100644 --- a/approvaltests/docs/tutorials/GettingStarted.md +++ b/approvaltests/docs/tutorials/GettingStarted.md @@ -27,7 +27,7 @@ ApprovalTests is a way to handle the second part: Verification. All calls will l ```java Approvals.verify(objectToBeVerified); ``` -snippet source | anchor +snippet source | anchor ## Strings @@ -38,18 +38,18 @@ Letʼs say you wanted to test if a string was being built correctly: ```java @Test -public void testBuildString() { - /* Do */ - // create a string with "Approval" and append "Tests" to it - String s = "Approval"; - s += " Tests"; - - /* Verify */ - // Verify the resulting string - Approvals.verify(s); +public void testBuildString() +{ + /* Do */ + // create a string with "Approval" and append "Tests" to it + String s = "Approval"; + s += " Tests"; + /* Verify */ + // Verify the resulting string + Approvals.verify(s); } ``` -snippet source | anchor +snippet source | anchor Will Produce the following File: @@ -81,15 +81,15 @@ Let's say that you wanted to test that a customized StringBuilder was creating t @Test public void testObject() { - /* Do */ - // create an 100 x 200 rectangle with the top corner at (5, 10) - Rectangle objectUnderTest = new Rectangle(5, 10, 100, 200); - /* Verify */ - // Verify the rectangle is properly defined - Approvals.verify(objectUnderTest.toString()); + /* Do */ + // create an 100 x 200 rectangle with the top corner at (5, 10) + Rectangle objectUnderTest = new Rectangle(5, 10, 100, 200); + /* Verify */ + // Verify the rectangle is properly defined + Approvals.verify(objectUnderTest.toString()); } ``` -snippet source | anchor +snippet source | anchor Will Produce the following File: @@ -113,7 +113,7 @@ If the object does not have a toString() method defined, and you do not want to ```java JsonApprovals.verifyAsJson(objectUnderTest); ``` -snippet source | anchor +snippet source | anchor Will Produce the following File: @@ -141,11 +141,35 @@ Method for objects you want to use. ## Arrays Letʼs say you wanted to test an array of Strings: -snippet: verifying_arrays + + +```java +@Test +public void testArray() +{ + /* Do */ + // create a String Array and set values in the indexes + String[] s = new String[2]; + s[0] = "Approval"; + s[1] = "Tests"; + /* Verify */ + // Verify the array + Approvals.verifyAll("Text", s); +} +``` +snippet source | anchor + Will Produce the following File: -snippet: GettingStartedTest.testArray.approved.txt + + +```txt +Text[0] = Approval +Text[1] = Tests +``` +snippet source | anchor + Note the use of the label, "Text". This is used to make the generated output easier to read: @@ -155,7 +179,19 @@ Again, simply [Approve The Result](#ApprovingTheResult) Letʼs say you wanted to test that youʼve created a JPanel correctly. (This works for anything that extends java.awt.Component : awt, swing, JFrame, Label, etc...) -snippet: verifying_gui + + +```java +/* Do */ +// create a TV Guide and select a show for 3pm +TvGuide tv = new TvGuide(); +tv.selectTime("3pm"); +/* Verify */ +// Verify the TvGuide +AwtApprovals.verify(tv); +``` +snippet source | anchor + SampleTest.testTvGuide.Mac_OS_X.approved.png ![Expected Image](ApprovalsTest.testTvGuide.Mac_OS_X.approved.png)