Not able to create test cases using diffblue intellij plugin

Hi @pooja_singhani,

This option can only be used in the CLI today; we are going to add this as an option in the plugin in an upcoming release

This option will only help you for writing tests where the sandboxing policy is protecting you from potentially dangerous code. Are we able to successfully write tests for other parts of your code that don’t exercise JMX APIs?

Thanks

Matt @ Diffblue

Yes, Able to create test case but one thing i need to confirm it will create multiple test cases for one method. This is default behavior OR we can change it.

Also when we get the new version of diffblue with “–disable-security-policy” option

Hi @pooja_singhani

Diffblue creates a test for each pathway in a method - so in this example from SpringPetclinic in our documentation:

@GetMapping("/owners")
public String processFindForm(@RequestParam(defaultValue = "1") int page, Owner owner, BindingResult result,
		Model model) {

	// allow parameterless GET request for /owners to return all records
	if (owner.getLastName() == null) {
		owner.setLastName(""); // empty string signifies broadest possible search
	}

	// find owners by last name
	String lastName = owner.getLastName();
	Page<Owner> ownersResults = findPaginatedForOwnersLastName(page, lastName);
	if (ownersResults.isEmpty()) {
		// no owners found
		result.rejectValue("lastName", "notFound", "not found");
		return "owners/findOwners";
	}
	else if (ownersResults.getTotalElements() == 1) {
		// 1 owner found
		owner = ownersResults.iterator().next();
		return "redirect:/owners/" + owner.getId();
	}
	else {
		// multiple owners found
		lastName = owner.getLastName();
		return addPaginationModel(page, model, lastName, ownersResults);
	}
}

We will write a test for each of the separate pathways thus covering all of the possible behaviour.

The option to --disable-security-policy in the plugin is currently scheduled within the next 4 weeks but this could change over time; I will keep you updated.

Can I ask what sort of project are you testing on and what are you looking to get from Diffblue Cover?

Thanks

Matt @ Diffblue

Project we are testing is mixed of BDD framework as well call external API’s and not able to create test cases for both due to “–disable-security-policy” option not available in plugin.

Hi @pooja_singhani,

Thanks for the information; what is the bigger picture of what you are trying to do? Are you looking to speed up development of new code or bulk increase coverage or something else?

Thanks

Matt @ Diffblue

We are looking for creation of JUNIT test cases with maximum coverage around 80% but it will provide around 60%-70%.

Can you please update when we get the option --disable-security-policy in diffblue plugin? Because you said it will be available in next 4 weeks.

Hi @pooja_singhani

This option has been added and is available in the Diffblue >> Settings menu option

To disable sandboxing uncheck the box - please ensure you understand the caution message.

Thanks

Matt @ Diffblue

Install latest version of diffblue cover plugin and when try to activate license return “Internal error”

Also brief about - which may damage your system environment when we disable sandboxing

Able to resolve it. But now return

R013 - No inputs found that don’t throw a trivial exception

I don’t have any idea about code. Can you please help me to resolve this issue?
Thanks in advance

Hi,
Regarding R013 please have a look at this page: Working with code R013 | Diffblue Docs
This has information on how to deal with this output code.
Regarding sandboxing you can find more information here on what sandboxing prevents: Working with code R011 | Diffblue Docs
Thanks Thomas @ Diffblue

Any more information that can help me to resolve R013 error code because i dont have any idea about code. just create a test cases. Can you please help on this?

Hi,
R013 is an output code that lets you know why Diffblue Cover did not generate tests for a specific class. How many R013s are you seeing your project? Is it just a single instance or spread through out the project?
To resolve a R013 it will require some user input as Diffblue Cover needs help to construct your class. So I understand, are you able to tell me more what you mean by you don’t have any idea about the code. Do you mean you are not able to refactor the code or do you need some more guidance with the options linked in the docs?
Thanks, Thomas @ Diffblue

Actually I don’t know what user input OR on what basis needs to provide to construct class. Can you help on this?

Hi,
The solution to this issue will be specific to your code and so I cannot make any suggestions with the current information as you are not able to share source code or log files. In order to help you further I will need more information, maybe you could provide some sample code that provides the same behaviour but you are able to share.
Thanks, Thomas

Please find below sample code -

@RestController
@RequestMapping(“/v1/info”)
@AllArgsConstructor
public class AppInfoController {

static final Logger log = LoggerFactory.getLogger(AppInfoController.class);

private AppInfoService AppInfoService;

@GetMapping
public ResponseEntity getAppInfo() {
log.info(“App Info flow started…”);
AppInfoResponse appInfoResponse = AppInfoService.getAppInfo();
return ResponseEntity.status(HttpStatus.OK).body(appInfoResponse);
}
}

@Service
@AllArgsConstructor
public class AppInfoService {

private BuildProperties buildProperties;

public AppInfoResponse getAppInfo() {
return AppInfoResponse.builder()
.name(buildProperties.getName())
.artifact(buildProperties.getArtifact())
.group(buildProperties.getGroup())
.version(buildProperties.getVersion())
.build();
}
}

@Getter
@Setter
@Builder
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AppInfoResponse {

private String name;
private String artifact;
private String group;
private String version;
}

sample code like this we are facing R013 error code. Can you please help on this?

Hi @pooja_singhani,

Thanks for the example code, this always helps when trying to reproduce something. I have created the classes in IntelliJ and run the Diffblue plugin to create tests. Everything was successful with the creation of three new test classes. I am running plugin Diffblue Cover Plugin version 2022.08.03.

For this simple example can you reply with the Diffblue plugin log file? I can then compare versions and anything else that might be different.

regards,

David @ Diffblue

Yes we also able to create test cases for this sample code. But sometimes not able to create test cases for mocking classes and methods. Can you please provide any solution for this?

Because still some of the service classes we are not able to create test cases.
If we get something it will be great help for us.

i need this on urgent basis please me out if any idea

Hi @pooja_singhani,

As per David’s message please can you provide the logfile so that we can investigate further

Thanks

Matthew