无法使用maven intellij运行spock测试



我正在尝试使用maven/intellij运行spock测试。但maven和intellij都没有选择测试类。它肯定会拾取类,但不会在类中执行任何测试。

这是我的spock测试类

class SpaceAccessorServiceTest extends Specification {
SpaceLookUpService spaceLookUpService = Mock()
SpaceAccessorService accessorService = new SpaceAccessorService();
def gsProxy = Mock(GigaSpace)
def setup() {
spaceLookUpService.getSpace(_ as String) << gsProxy
}
def 'should call readmultiple function on gigaspace proxy to get all objects from space for typename'() {
given 'environment name'
String envName = 'Grid-A'
String dataType = 'data'
String criteria = 'some-criteria'
when 'call space accessor service to get all objects from space for typename'
accessorService.getAllObjectsFromSpaceForTypeName(envName, dataType, criteria)
then 'readMultiple method is invoked on gigapsace proxy'
1 * gsProxy.readMultiple(_ as SQLQuery)
}
}

来自maven 的O/p

T E S T S
-------------------------------------------------------
Running com.ambuj.SpaceAccessorServiceTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.369 sec
There are no tests to run.
Results :

智能控制台的O/p

java.lang.Exception: No tests found matching Method should call readmultiple function on gigaspace proxy to get all objects from space for typename(com.ambuj.SpaceAccessorServiceTest) from org.junit.internal.requests.ClassRequest@5aaa6d82
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:40)

我已经检查了

1) grovvy-all和spock-libs添加到类路径中,可以在模块设置的依赖项选项卡中看到它们

2) Surefire插件配置正确,因为它会拾取用于测试的文件

3) 在目标/测试类文件夹中生成的测试类

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<includes>
<include>**/*Test.class</include>
<include>**/*Spec.class</include>
</includes>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.8.1</version>
</dependency>
</dependencies>
</plugin>

我在这里应该缺少什么需要帮助。

可能已经晚了,但我只是想强调一下@Steinar的评论也解决了我的问题。

作为第一次使用Spock的用户,我也犯了同样的错误,在规范中没有标签given:when:then:。然后偶然发现了这个问题,找到了Steinar的评论。

最新更新