- Developer Workflow
- Running Approvals
- Add Behavior to Existing Approval
- New Approval
- TDD and ApprovalTests
- Tactics
For Intention Only: Diagram representing the workflow of a dev using approval tests The user will have tasks User tasks / actions User sees
digraph G { node [style=filled, shape=rect]
- Separate steps with user vs automatic
User would do:
- approvaltests already installed
- user does: write new test -> run the test
flowchart
Run --> capture(Captures Snapshot) --> comp(Compares Snapshot) --> Passes
comp --> Fails
Fails --> reporter["Open Reporter (Diff Tool)"]
If you are fixing a bug (or adding a feature), this will change the expected behavior. Therefore when you run the test, it will fail.
flowchart
mod(Modify Code) --> run(Run Test)
--> fail["Fail (Expected)"]
--> diff(Diff Tool)
--> compare(Review Changes)
-->wanted[Wanted Change]
style wanted fill:#0f0
compare --> unwanted(Unwanted Change)
style unwanted fill:#f00
unwanted --> mod
wanted --> approve(Approve New File)
Because the .approved
file does not exist when writing a new test, the test will always fail the first time you run it.
flowchart
write(Write Test)
--> code(Write Code)
--> runt(Run Test)
--> fail["Fail(Forced)"]
--> diff(Diff Tool)
--> review(Review Result)
--> complete(Feature Complete)
review --> incomplete(Feature Incomplete)
complete --> approve(Approve New File)
incomplete --> code
style incomplete fill:#f00
style complete fill:#0f0
Test Driven Development usually follows this path:
flowchart
write("Write Test\n(with Expected Result)") -->
red(See it Fail) -->
code(Write Code) -->
green(See it Pass) -->
refactor(Refactor) --> write
code --> red
style red fill:#f00
style green fill:#0f0
The ApprovalTests loop is slightly different than traditional TDD. It splits the writing of the test into 2 parts:
- Writing the Test
- Capturing the Expected Result
And moves the capturing of the expected result to after the code is written.
flowchart
write("Write Test\n(without Expected Result)") -->
code(Write Code) -->
assess(Assess the Result) -->
approve(Approve it:\n Capture Expected Result) --> refactor(Refactor) --> write
assess --> code
style approve fill:#0f0
Copying from the recieved into the appproved. This can be done on the file system or directly in the diff tool.
"Expected Failure" -> {"failure2", "Pass (unexpected)"} GOAL: capture the Expected result use Approval Tests to KEEP TRACK of passing tests