
119
dataFile.each_line do | line |
desc, action, part2 = line.split(",")
sourceXml, expectedHtml, leftOver = part2.split(",")
if "crossref"==action.strip
generateAndVerifyHtml sourceXml, expectedHtml, desc
else # new "verbs" go before here as elsif's
report_error( "unknown action" + action.strip )
end
end
end
Here is the comma-delimited data fi le that the Data-Driven Test method reads:
ID, Action, SourceXml, ExpectedHtml
Extref,crossref,<extref id='abc'/>,<a href='abc.html'>abc</a>
TTerm,crossref,<testterm id='abc'/>,<a href='abc.html'>abc</a>
TTerms,crossref,<testterms id='abc'/>,<a href='abc.html'>abcs</a>
Avoiding Conditional Test Logic
Another thing we want to avoid in our tests is conditional logic. Conditional
Test Logic (page 200) is bad because the same test may execute differently in
different circumstances. Conditional Test Logic reduces our trust in the tests
because the code in our Test Methods is Untestable Test Code. Why is this
important? Because the only way we can verify our Test Method is to manually
edit the SUT so that it produces the error we want to be detected. If the Test
Method has many paths through it, we need to make sure each path is coded
correctly. Isn’t it so much simpler just to have only one possible execution path
through the test? Let us look at some reasons why we might include conditional
logic in our tests:
• We don’t want to execute certain assertions because their execution
doesn’t make sense given what we have already discovered at this point
in the test (typically a failure condition).
• We have to allow for various situations in the actual results that we are
comparing to the expected results.
• We are trying to reuse a Test Method in several different circumstances
(essentially merging several tests into a single Test Method).
The problem with using Conditional Test Logic in the fi rst two cases is that it
makes the code hard to read and may mask cases of reusing test methods via
Flexible Tests (see Conditional Test Logic). The last “reason” is just a bad idea,
Avoiding Conditional Test Logic