Description
Description
In order to validate method's correctness, humans do not write regression tests with null values. Especially for successful tests.
Null values can be the easiest way to cover a branch. But human readability of such tests is not very good.
Expected behavior
When null value(s) are added to path constraints, then they should be used in the execution.
But if null value is not necessary for a particular branch of execution, it is suggested to generate instances of input parameters.
Also need to consider if minimization needs to be adjusted accordingly.
So that executions with not-null values are of higher priority.
Environment
IntelliJ IDEA
CLI
Potential alternatives
Add setting to change priority of null / not null input parameters.
Context
Example of generated test with null values:
///region Test suites for executable org.springframework.samples.petclinic.owner.OwnerController.findOwner
///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method findOwner(java.lang.Integer)
@Test
@DisplayName("findOwner: ownerId == null : False -> return ownerId == null ? new Owner() : this.owners.findById(ownerId)")
public void testFindOwner_OwnerIdNotEqualsNull() {
(when(ownerRepositoryMock.findById(any()))).thenReturn(((Owner) null));
Integer ownerId = 0;
Owner actual = ownerController.findOwner(ownerId);
assertNull(actual);
}
///endregion
///endregion
Test more suitable for a regression suite:
///region Test suites for executable org.springframework.samples.petclinic.owner.OwnerController.findOwner
///region SYMBOLIC EXECUTION: SUCCESSFUL EXECUTIONS for method findOwner(java.lang.Integer)
@Test
@DisplayName("findOwner: ownerId != null -> return Owner")
public void testFindOwner_OwnerIdNotEqualsNull() {
Owner owner = new Owner();
Integer ownerId = 222;
owner.setId(ownerId);
(when(ownerRepositoryMock.findById(ownerId))).thenReturn(owner);
Owner actual = ownerController.findOwner(ownerId);
deepEquals(owner, actual);
}
///endregion
///endregion
Metadata
Metadata
Assignees
Labels
Type
Projects
Status