What's New > Version 2020.12.01
Enhancements to mocking void methods and improvements to generated assertions
Release date: Dec 08, 2020
Mocking void methods
When mocking void methods, we now add a Mockito.verify()
statement which asserts on the number of invocations, this allows you to get a test even if there isn’t anything else to assert on.
verify(this.simpleService_AdditionService, times(2)).makeAGoodGuess(anyInt(), anyInt());
Asserting on methods that return a boolean
Assertions are now generated for both true
and false
values of methods that return a bool
value from straight-line code.
@Test
public void testIsAssignableFrom() {
// Arrange, Act and Assert
assertFalse(Bird.isAssignableFrom(Object.class));
assertTrue(Bird.isAssignableFrom(Owl.class));
}
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. We will give you these tests and a nice reminder to complete the tests by adding assertions.
Full Release Notes
Enhancements
-
CLI: Cover’s logging, to the console when using
--verbose
, or to the log file, has been improved so that it is easier to read per-class and per-method messages. [Ref: TG-13323] -
IntelliJ Plugin: Cover now supports IntelliJ IDEA Community Edition 2020.3 and IntelliJ IDEA Ultimate 2020.3. [Ref: TG-13292]
-
Cover is now able to verify if a mocked method, which returns
void
, has been called. [Ref: TG-13199] -
Cover is now able to verify if a mocked method has been called more than once. [Ref: TG-13198]
-
Cover now uses
isEmpty()
, rather than comparing 0 withlist.size()
, when writing assertions for empty collections such as aset
,list
ormap
. [Ref: TG-13169] -
Cover is now able to assert on the content of a repository when testing
void
Repository methods. [Ref: TG-12970]
Resolved Issues
-
IntelliJ Plugin: Resolved an issue where the
test
classpath wasn’t consulted when writing tests on Gradle projects. [Ref: TG-13301] -
CLI: Resolved an issue where Cover may fail to download the project’s dependencies on Maven Central. [Ref: TG-13278]
-
CLI: Resolved an issue where tests were discarded with V002 error code for Spring Repositories. [Ref: TG-13274]
-
IntelliJ Plugin: Resolved a cosmetic issue, within Cover’s ‘Spring’ settings, so that it is clearer when mocking will be used. [Ref: TG-13271]
-
IntelliJ Plugin: Resolved an issue where selecting ‘Write tests’ may fail with
Could not initialize class oshi.software.os.windows.WindowsOperatingSystem
orFailed to create temporary file for /com/sun/jna/win32-x86-64/jnidispatch.dll library
. [Ref: TG-13235] -
IntelliJ Plugin: Resolved an issue where, the JDK path provided to IntelliJ is inaccessible,
Failed to start remote test generation service
may be logged. Cover now provides improved guidance. [Ref: TG-13200]
Known Issues
-
CLI: Windows: creating
config.json
by outputting--example-config
as file causes exceptions. [Ref: TG-11198] -
CLI: All tests may be discarded in test validation 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 validation may fail on a Gradle project due to an incompatibility between Gradle and Cover. If you encounter this issue, run with
--skip-test-validation
. [Ref: TG-12045] -
IntelliJ Plugin: Large multi-module Gradle projects may take a long time to index. [Ref: TG-12923]