TwiP

Add parameters to your JUnit test methods
Download

TwiP Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Freeware
  • Price:
  • FREE
  • Publisher Name:
  • Snackbox
  • Publisher web site:
  • Operating Systems:
  • Mac OS X
  • File Size:
  • 15 KB

TwiP Tags


TwiP Description

Add parameters to your JUnit test methods "Tests with Properties" allows you to simply add parameters to your JUnit test methods. TwiP calls them with all possible combinations of these parameters... or at least some commonly failing values in the case of Integers, etc. TwiP is especially useful, if you want to test all values of an enum or combinations of some flags.Alternatively you can specify a static method or field to provide the values for your test method(s), if you want to test with other than the default values.Note that the number of test cases can grow quickly in this way, but the test code usually turns out to be much cleaner. Traditionally you write two methods to test two fixtures. They generally differ in just one or two statement. You can refactor some fixture setup or assertion code into an utility method, but it is often difficult to even find a good name for such methods, which generally indicates a bad practice. By adding a boolean argument to your first test method, you can add your second fixture with a simple if statement. The same thing sometimes works for enums as well: If you want to check that all possible values are handled correctly, you can pass it as an argument. Frequently even the variations in the assertion code can be phrased in a very concise way, so this is a much better option over writing one test method for say every possible enum value.A good example of how concise assertion code can be, is the inverse of a mathematical operation. Say you want to test if your multiplication code is correct. Instead of writing hundreds of test methods all by the same pattern with only the numbers different, you can write one method with two integer arguments. The assertion simply checks that dividing the result of your multiplication by one argument returns the other.So TwiP is comparable to the experimental Theories Runners that is built into JUnit since version 4.4 (see here ), but I think TwiP is much easier to grasp and handle, although the theory behind TwiP is the same as that for the Theories runner. Requirements: · Java


TwiP Related Software