technology:opinions:abiasedguidetounittests
                Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| technology:opinions:abiasedguidetounittests [2021/09/06 22:34] – Owen Mellema | technology:opinions:abiasedguidetounittests [2021/09/06 22:52] (current) – Owen Mellema | ||
|---|---|---|---|
| Line 323: | Line 323: | ||
| //Feed packaged input into SUT | //Feed packaged input into SUT | ||
| - | FibonacciResponse packagedOutput = Fibonacci.fib3(fibonacciCriteria); | + | FibonacciResponse packagedOutput = Fibonacci.fib(fibonacciCriteria); | 
| //Create a packaged expected output. | //Create a packaged expected output. | ||
| Line 413: | Line 413: | ||
| </ | </ | ||
| ==== Effective abstraction ==== | ==== Effective abstraction ==== | ||
| - | Here's a few ideas for cleaning up your tests with abstraction. | + | Here's a few ideas for cleaning up your tests with abstraction. Remember, in all of this, the name of the game is // | 
| * Do as little packaging in your setup methods as possible. Instead, move the heavy lifting of packaging to dedicated private methods, like this: | * Do as little packaging in your setup methods as possible. Instead, move the heavy lifting of packaging to dedicated private methods, like this: | ||
| < | < | ||
| Line 449: | Line 449: | ||
| </ | </ | ||
| * Don't abstract away the actual calling of the SUT. After all, that's the most important part. | * Don't abstract away the actual calling of the SUT. After all, that's the most important part. | ||
| + | * Writing helper assertion methods can be helpful, but they can also confuse readers if not done right. Follow these tips to write a good helper assert. | ||
| + |     * Your assertion should take two arguments at most (excluding housekeeping arguments like " | ||
| + | * The first argument should be the packaged output, and the second argument should be the primitive to test. | ||
| + |     * The name of the helper should begin with " | ||
| + | * All asserts in the helper assertion method should be conceptually related. If possible, use just one. | ||
| + | < | ||
| + | @Test | ||
| + | void thenResultIs0() { | ||
| + |     assertResult(response, | ||
| + | } | ||
| + | |||
| + | private void assertResult(FibonacciResponse response, int expectedResult) | ||
| + | { | ||
| + |     int result = response.getResult(); | ||
| + |     assertEquals(expectedResult, | ||
| + | } | ||
| + | </ | ||
technology/opinions/abiasedguidetounittests.1630967652.txt.gz · Last modified: 2021/09/06 22:34 by Owen Mellema
                
                