Java Magazine, Nov/Dec 2016
ORACLE COM JAVAMAGAZINE NOVEMBER DECEMBER 2016 53 junit 5 removed conditional replaced equality check with false Pitest has changed the method to this private boolean areEqual double actual double expected double tolerance if false return true mutated if expected length actual length return false return compareArrayContents actual expected tolerance I cant refactor the equivalent mutant away without losing the performance optimization So not all equivalent mutants are helpful but they are less common than the research suggests Pitest is designed to make equivalent mutants as unlikely as possible using the default set of operators many teams never encounter one How many you see depends on the type of code you are writing and your coding style What About Really Big Projects None of the example projects Ive talked about so far has been huge Is it possible to use mutation testing on a really big project Yes As I have discussed by far the most efective way to use mutation testing is to run tests as you are developing code When you use it in this way project size doesnt matter For a project such as Truth it is simplest to mutate the entire project each time but you dont need to do this The only code you need to perform mutation testing on is code that youve just written or changed Even if your codebase contains millions of lines of code it is unlikely that your code change will afect more than a handful of classes Pitest makes it easy to work in this way by integrating with version control systems This functionality is currently available only when using the Maven plugin If you have correctly configured the standard Maven version control information in your POM file you can analyze just your locally modified code using pitests scmMutation Coverage goal This goal has been bound to the profile pitest local in the Google Truth POM mvn Ppitest local test If you havent made any changes to the checked out code this goal will run the tests and then stop If you have made changes it will analyze only the changed files Make a change now to try it out This approach gives you just the information you need Is the code youre currently working on well tested Pitest can also be set up so that a continuous integration CI server can analyze just the last commit But what if you want a complete picture of how good the tests are for a whole project Eventually you will hit a limit for how large a project you can do mutation testing for unless you are willing to wait for many hours but pitest does provide an experimental option to push that limit further Go back to the Google Truth project and run it with the following mvn DwithHistory Ppitest test Nothing will seem very diferent from when you ran it before
You must have JavaScript enabled to view digital editions.