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.