Im using spockframework
and junit5
, below is pom:
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.10</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>1.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.spockframework/spock-core -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.1-groovy-3.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.spockframework/spock-spring -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>2.1-groovy-3.0</version>
<scope>test</scope>
</dependency>
When run class Spec
(as same as Test of junit) i face below exception:
org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' failed to discover tests
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:160)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverSafely(EngineDiscoveryOrchestrator.java:134)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discover(EngineDiscoveryOrchestrator.java:80)
at org.junit.platform.launcher.core.DefaultLauncher.discover(DefaultLauncher.java:110)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.junit.platform.commons.PreconditionViolationException: Could not find method with name [should convert toEntity for worker] in class [com.myapp.converter.ApplicationConverterSpec].
at org.junit.platform.engine.discovery.MethodSelector.lambda$lazyLoadJavaMethod$2(MethodSelector.java:176)
at java.base/java.util.Optional.orElseThrow(Optional.java:408)
at org.junit.platform.engine.discovery.MethodSelector.lazyLoadJavaMethod(MethodSelector.java:174)
at org.junit.platform.engine.discovery.MethodSelector.getJavaMethod(MethodSelector.java:149)
at org.junit.vintage.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:36)
at org.junit.vintage.engine.discovery.MethodSelectorResolver.lambda$resolve$0(MethodSelectorResolver.java:30)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.vintage.engine.discovery.MethodSelectorResolver.resolve(MethodSelectorResolver.java:30)
at org.junit.vintage.engine.discovery.VintageDiscoverer.collectTestClasses(VintageDiscoverer.java:64)
at org.junit.vintage.engine.discovery.VintageDiscoverer.discover(VintageDiscoverer.java:51)
at org.junit.vintage.engine.VintageTestEngine.discover(VintageTestEngine.java:61)
at org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.discoverEngineRoot(EngineDiscoveryOrchestrator.java:152)
... 13 more
this issue happen when i right-click to run single test case. and it's working fine if i run maven or whole test class.
Not the big issue but i gonna find out why.
Thanks
=====Edit=====
Here is my spec
and now it working fine without any changes (just few time clean build and restart IDE \
import com.fleetrecruitment.common.ApplicantDO
import com.fleetrecruitment.hsf.dto.masterdata.Gender
import com.fleetrecruitment.hsf.dto.masterdata.Photo
import com.fleetrecruitment.mapper.CommonMapperImpl
import com.fleetrecruitment.enums.GenderOption
import com.fleetrecruitment.hsf.dto.applicant.WorkerApplicant
import org.junit.jupiter.engine.JupiterTestEngine
import spock.lang.Specification
class ApplicationConverterSpec extends Specification {
private ApplicantConverter converter
def setup(){
converter = new ApplicantConverterImpl();
converter.commonMapper = new CommonMapperImpl();
converter.redmartCommonConverter = new RedmartCommonConverterImpl();
JupiterTestEngine o = new JupiterTestEngine();
}
def "should convert toEntity for worker"(){
when:
ApplicantDO entity= converter.toEntity(givenWorker)
then:
with(entity){
name == expEntity.name
phoneNumber == expEntity.phoneNumber
gender == expEntity.gender
with(idPhotos.get(0)){
bizType == expEntity.idPhotos.get(0).bizType
name == expEntity.idPhotos.get(0).name
}
}
where:
givenWorker << [
new WorkerApplicant( name: "Trung.do", phoneNumber: "123456", gender: GenderOption.FEMALE,
idPhotos: "[{\"name\": \"abc.jpg\", \"bizType\": \"logistics-fleet-recruitment\", \"ossObjectKey\": \"268d129bcd894a25a44849f26d44bba3_3e8cd422be83474ab992b9d41018840f.jpg\"},{}]" )
]
expEntity << [
new ApplicantDO(name: "Trung.do", phoneNumber: "123456", gender: Gender.FEMALE,
idPhotos: [new Photo(bizType:"logistics-fleet-recruitment", name: "abc.jpg")]
)
]
}
}