Several tools exists that allow to calculate path coverage for a set of tests, but is there a tool (or an algorithm) that could suggest values to get the best path coverage with the smallest number of tests possible?
For example with the following classes:
public class User {
private boolean isAdmin = false;
private String name;
private String password;
public User(String name, String password, boolean isAdmin) {
this.name = name;
this.password = password;
this.isAdmin = isAdmin;
}
public boolean isAdmin() {
return isAdmin;
}
public boolean authenticate(String name, String password) {
if (name.equals(this.name) && password.equals(this.password)) {
return true;
} else {
return false;
}
}
}
public class DataRepository {
List<String> data = new ArrayList<String>();
public void add(String dataPiece) {
data.add(dataPiece);
}
public void clearAll(User userAuthenticated) {
if (userAuthenticated.isAdmin()) {
data.clear();
}
}
public void addAll(User userAuthenticated, List<String> collection) {
if (userAuthenticated.isAdmin()) {
data.addAll(collection);
}
}
}
I will get a better test coverage if i create a test which is using a User with isAdmin at true.
Is there a tool that could mention: if you create a test with User with isAdmin at true you will get the best test coverage.
Something like that but for more complicated cases, and that checks all the branches of code.
To answer your question about suggesting values for tests, you could possibly take a look at Agitar (http://www.agitar.com/). I remember having a presentation about it yonks ago and I’m sure it has changed (hopefully for the better) since then, but it might be what you’re looking for. I, myself, would continue to go down the route of TDD and the other things I mentioned in my other answer, but if you’re interested, here’s a little part of what the Agitar site has to say:
“The AgitarOne product family helps you work safer, better, and smarter as you develop and maintain your Java applications. AgitarOne JUnit Generator creates thorough JUnit tests on your code. This helps you find regressions and makes it safer and easier to improve your code to reduce the cost to maintain it.”