Hi there,
I’m evaluating yet diffblue for my company (using IntelliJ plugin).
I’ve created and simple spring webmc project in whitch i’ve got a simple Rest Controller with a @GetMapping method to retrieve a restaurant menue.
A menue has a name and is composed with a list of dessert, starter and dishes :
@Data
@Valid
public class Menue{
@NotNull
private String name;
@Valid
@Size(min=1)
private List<Starter> starters
...
}
Before serving data to the response of the call, i manualy try to validate that my menu is valid, using Javax.validation annotation on my output DTO, and using
set<ConstraintViolation<Menue>> violations = validator.validate(Menue);
if there are no violation, then the menue is sent as a response to the request, if there are violations, i throw an exception.
if(contraint.isEmpty()){
return menue
}
throw new RuntimeException ...
What i see, is that diffblue correctly create one test with a valid case :
- Diffblue mocks correcty my controller dependencies even my validator
- Diffbule initialize correcly the mocks.
Never the less, it seems that diffblue doesn’t generate a case where the validator mock returns one or more violations.
So basicaly a part of my controller is not covered.
My question here, could diffblue analyse javax.validation annotation to generate test cases according to the validation annotations ?
An other point on diffblue, the generated test output differs when
- a spring annotated service will produce a spring test with mock injection at class level
- the same service without spring annotation will produce a simple unit test with mock injection at method level
- the same service where injected beans are not implementing interface will leads to a unit test withtout mocks
I didn’t find on your documentation some chapter explaining how to structure the code to have a specific test generation output. So i’m diving manualy to figure out what is the behaviour of diffblue.
And maybe a last topic : name of the generated test method are not really helpfull : it generates something like : testMethod1, testMethod2, testMethod3 whereas i would exepect something more descriptive like : testMethodWithParamXEmpty, testMethodWithInvalidXparameter …
That said, i’m very pleased about diffblue, the potiential of diffblue is really good.
Have a nice day.
Michael