pitest report NO_COVERAGE
NO_COVERAGE, why?
- mutated return of Object value for com/hello/mercury/utils/DateUtils::getStartOfDay to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE
main code: public static Timestamp getStartOfDay(Timestamp timestamp){ LocalDateTime localDateTime = timestamp.toLocalDateTime(); LocalDateTime startDateTime = localDateTime.toLocalDate().atStartOfDay(); return Timestamp.valueOf(startDateTime); }
Test code: @Test public void testGetStartOfDay() { Assert.assertNotNull(dateUtils.getStartOfDay(null)); // 1月13号00:00:00 Timestamp timestamp1 = new Timestamp(1578844800000L); // 1月13号19:56:35 Timestamp timestamp2 = new Timestamp(1578916595000L); Assert.assertEquals(Timestamp.valueOf("2020-01-13 00:00:00.0"), dateUtils.getStartOfDay(timestamp2)); // 1月13号23:59:59 Timestamp timestamp3 = new Timestamp(1578931199000L); Assert.assertEquals(Timestamp.valueOf("2020-01-13 00:00:00.0"), dateUtils.getStartOfDay(timestamp3)); // 1月14号05:20:38 Timestamp timestamp4 = new Timestamp(1578950438000L); Assert.assertEquals(Timestamp.valueOf("2020-01-14 00:00:00.0"), dateUtils.getStartOfDay(timestamp4)); }
From some reason that test is not being run, or does not do what you think it does. If you can post a complete executable example that reproduces the issue I can take a look.
Based on the code you have pasted (and then edited?) possible issues might be a missing @Test annotation, or this test is executing a different (but simililarly named class.
i've resolved the problem when i change to use juit test case, does'nt pitest support testng?
You should set testPlugin as testng on pom.xml (if you're using maven), or build.gradle (if you're using gradle) Maven example:
<build>
<plugins>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.5.1</version>
<configuration>
<targetClasses>
<param>your.project.package.*</param>
</targetClasses>
<targetTests>
<param>your.project.package.*</param>
</targetTests>
<testPlugin>testng</testPlugin>
</configuration>
</plugin>
</plugins>
</build>
Gradle example:
plugins {
id "info.solidsoft.pitest" version '1.5.1'
}
pitest {
testPlugin = 'testng' //Set TestRunner as TestNGs
targetClasses = ['your.project.package.*'] //Include all repo's packages
targetTests = ['your.project.package.*']
}
This is documented at pitest maven quickstart and it's located at this file from gradle plugin (I copied the related comments below)
/**
* Specifies what test plugin to use.
*
* Prior to 1.3.0 this was autodetected, now it has to be specified. The junit plugin is used by default.
*
* For using with JUnit 5 please see: junit5PluginVersion
*
* @since 1.3.0
*/
final Property<String> testPlugin