What's New > Version 2021.02.02

Enhancements to test generatation

Release date: Feb 15, 2021

Cover now produces useful assertions for methods using the Eclipse collection libraries

  public class Iterables {
      public static RichIterable<String> someMoreStrings() {
          return UnmodifiableRichIterable.of(HashBag.newBagWith("x", "y", "z"));
      }
  }

Now produces the following test:

  public class IterablesDiffblueTest {
      @Test
      public void testSomeMoreStrings() {
          // Arrange and Act
          RichIterable<String> actualSomeMoreStringsResult = Iterables.someMoreStrings();
          // Assert
          assertEquals("z", actualSomeMoreStringsResult.getAny());
          assertEquals("[z, y, x]", actualSomeMoreStringsResult.toString());
          assertEquals("x", actualSomeMoreStringsResult.getLast());
          assertEquals(3, actualSomeMoreStringsResult.size());
          assertFalse(actualSomeMoreStringsResult.isEmpty());
          Iterator<String> iteratorResult = actualSomeMoreStringsResult.iterator();
          assertTrue(iteratorResult.hasNext());
          assertEquals("z", iteratorResult.next());
      }
  }

Cover now creates tests using static final fields, instead of their values, when appropriate

    @Test
    public void testComputeOutChannel() throws InterruptedException {
      // Arrange
      MessageProcessor messageProcessor = new MessageProcessor();
      MessageImpl messageImpl = mock(MessageImpl.class);
          when(messageImpl.getProperty(anyString())).thenReturn(Boolean.TRUE.toString());
      when(messageImpl.getKey()).thenReturn(MessageRouter.KEY_TRANSACTION);
      when(messageImpl.hasProperty(anyString())).thenReturn(true);
      GrowableArrayBlockingQueue<Object> growableArrayBlockingQueue = 
          new GrowableArrayBlockingQueue<Object>();
      growableArrayBlockingQueue.offer(messageImpl);
      // Act and Assert
      assertEquals(MessageRouter.OUT_URGENT,
          messageProcessor.computeOutChannel((Message) growableArrayBlockingQueue.take()));
  }

Improvements to MUTs with no side effect

Cover now creates better test cases for scenarios where the invocation of the method under test has no side effects, asserting that nothing has changed after the execution of the method

  public class MagicTripleDetector {
      private boolean sawMagicTriple = false;
      public boolean sawMagicTriple() {
          return sawMagicTriple;
      }
      public void checkTriple(int a, int b, int c) {
          if (a * b + 17 == 23 * c)
              sawMagicTriple = true;
      }
  }

Now produces the following test:

  public class MagicTripleDetectorTest {
      @Test
      public void testSawMagicTriple() {
          // Arrange, Act and Assert
          assertFalse((new MagicTripleDetector()).sawMagicTriple());
      }
  
      @Test
      public void testCheckTriple() {
          // Arrange
          MagicTripleDetector magicTripleDetector = new MagicTripleDetector();

          // Act
          magicTripleDetector.checkTriple(1, 1, 1);

          // Assert that nothing has changed
          assertFalse(magicTripleDetector.sawMagicTriple());
      }
  }   

Feedback

If you have feedback, questions or requests regarding the Diffblue Cover IntelliJ Plugin, please contact us on the community forum. We would love to hear about what is important to you and what you would like to see in upcoming releases.

How do I automatically maintain all of these tests?

Use Diffblue Cover on any CI platform to automatically update your unit tests and catch regressions for every commit - watch this video to learn more.


Full Release Notes

Enhancements

  • Cover now produces useful assertions for methods using the Eclipse collection libraries. [Ref: TG-13689]

  • Cover now has improved compatibility for Spring projects which define interfaces that extend JpaRepository. [Ref: TG-13679]

  • Cover now creates tests using static final fields, instead of their values, when appropriate. [Ref: TG-13677]

  • Cover now creates tests which have Mockito verify assertions on void methods. [Ref: TG-13550]

  • Cover now creates better test cases for scenarios where the invocation of the method under test has no side effects, asserting that nothing has changed after the execution of the method. [Ref: TG-13531]

  • Cover now creates Spring tests for Spring methods (in @Controller, @Component and @Service classes) in a package without a configuration or application class. [Ref: TG-13452]

  • Cover’s log file and console output have been improved to increase readability. [Ref: TG-13206]

Resolved Issues

  • CLI: Resolved an issue where the use of --existing-coverage and --merge lead to an error being reported and no tests being generated. [Ref: TG-13699]

  • CLI: Resolved an issue where the user command passed through --validation-command wasn’t considered whilst running the environmental checks. [Ref: TG-13635]

  • Resolved an issue where Cover failed to pass suitable subtypes as arguments. [Ref: TG-13617]

  • Resolved an issue where, when creating tests for methods which are interfaces, Cover was using the type declared by the underlying method resulting in E009 errors. Cover now uses the actual returned instance’s class type. [Ref: TG-13518]

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]

  • IntelliJ Plugin: Diffblue Cover was unable to create an index error may appear if switching project happens before indexing completion. [Ref: TG-13772]