What's New > Version 2020.11.04
Support for Spring ActiveProfile and improvements in assertion generation
Release date: Nov 24, 2020
Assertions on methods that return Maps, Lists & Sets
assertEquals("Dr Jane Doe", list.get(1));
assertEquals(7, readFromDBResult.getAccounts().size());
Diffblue now generates assertions for methods that return Maps, Lists & Sets - we now generate assertions on the content of the list and parameters such as size.
Support for Spring @Profile
@Profile("dev")
public String initCreationForm(Map<String, Object> model) {
...
Your Spring project may use different configuration profiles, for example, dev, test, and prod, which distinguish the environment your application is running in. Diffblue Cover now allows you to set the Spring @Profile to use in the plugin settings page. Typically, for use with Diffblue Cover you’ll need to use a profile that allows you to run your tests without accessing systems that are only available in the production environment.
But how do I maintain all of these tests?
Use Diffblue Cover on any CI platform to automatically update your unit tests and catch regressions for every commit made by every developer - watch this video to learn more!
Cover gives you tests when we can’t find assertions
@Test public void testSetVisitsInternal() {
// TODO: This test is incomplete - see https://diff.blue/R004
// Reason: No meaningful assertions found.
// To help Diffblue Cover to find assertions, please add getters to the
// class under test that return fields written by the method under test.
Pet pet = new Pet();
pet.setVisitsInternal(this.collection);
}
Sometimes Diffblue Cover can arrange a test and create the objects but can’t find any valid assertions. From this release we will give you these tests and a nice reminder saving you a bunch of time 👍
Full Release Notes
Enhancements
-
IntelliJ Plugin: Cover is now able to create incomplete tests, if it was unable to find a suitable assertion. Incomplete tests contain a
//TODO
comment providing further guidance. This behavior is controllable via the plugin settings and turned on by default. [Ref: TG-13114] -
Cover now produces assertions on the content of
List
containers in more circumstances. [Ref: TG-13045] -
Cover now produces assertions on the size of
List
,Map
andSet
containers in more circumstances. [Ref: TG-13044] -
CLI: Cover now logs a message to the console if a class, necessary to write a test, is missing. [Ref: TG-13011]
-
Cover’s logging and guidance, in scenarios where dependencies are missing, has been improved. [Ref: TG-13007]
-
Cover is now able to create tests that set the Spring active profile (
@ActiveProfiles
annotation) as specified by the--active-profiles
CLI option or via the ‘Active Profiles’ plugin setting. [Ref: TG-11506]
Resolved Issues
-
CLI: Resolved an issue where, whilst attempting to write tests for some methods,
Exception: java.lang.AssertionError: This should never happen
may be incorrectly logged to the console. [Ref: TG-13143] -
CLI: Resolved an issue where, on some Maven projects,
We cannot load the Spring Boot application
may be logged to the console. [Ref: TG-13137] -
CLI: Resolved an issue where using
--verbose
results in each testable method being logged to the console twice. Duplicate logging was also present in log files. [Ref: TG-13105] -
IntelliJ Plugin: Resolved an issue where Cover may unnecessarily rescan
.jar
files during indexing. [Ref: TG-13080] -
IntelliJ Plugin: Resolved an issue where
Logfile location
is incorrectly shown, as a notification, each time ‘Write tests’ is selected. [Ref: TG-13051] -
IntelliJ Plugin: Resolved an issue where, in some cases, whilst attempting to write tests for a method,
Unable to construct TIR
and superfluous details are logged to the IntelliJ event log. [Ref: TG-13050] -
IntelliJ Plugin: Resolved an issue where, when ‘Generate boilerplate tests’ is enabled, the IntelliJ event log shows an attempt to write a test for a method which is considered not valuable to test. [Ref: TG-13049]
-
IntelliJ Plugin: Resolved an issue where, in some cases, closing an IntelliJ project whilst Cover is indexing may lead to an
AssertionError
being shown. [Ref: TG-12809]
Known Issues
-
Wrong reason for not creating essential tests for methods in classes without accessible constructors. [Ref: TG-10794]
-
CLI: Windows: creating
config.json
by outputting--example-config
as file causes exceptions. [Ref: TG-11198] -
CLI: All tests may be discarded in test verification when using
--config
. [Ref: TG-11475] -
CLI:
dcover clean --working-directory
throws an error if--test-output-dir
is not provided. [Ref: TG-11665] -
CLI: dcover fails to generate tests, reporting
java.lang.OutOfMemoryError
, when analysing projects which spawn a quantity of threads in excess of the operating system’s process thread limit. [Ref: TG-11680] -
CLI:
dcover clean --failing
fails when used with a Gradle project. [Ref: TG-11707] -
CLI: Test verification may fail on a Gradle project due to an incompatibility between Gradle and Cover. If you encounter this issue, run with
--skip-test-verification
. [Ref: TG-12045] -
IntelliJ Plugin: Large multi-module Gradle projects may take a long time to index. [Ref: TG-12923]
Dependencies for written tests
- JUnit: 4.7-5.7