无法使用maven intellij运行spock测试

时间:2016-06-09 20:22:17

标签: java maven intellij-idea 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 :

intellij控制台的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库添加到classpath中,能够在模块设置的依赖项选项卡中看到它们

2)Surefire插件配置正确,因为它选择了要测试的文件

3)在target / test-classes文件夹中生成的测试类

<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>

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

1 个答案:

答案 0 :(得分:0)

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

作为Spock的首次用户,我也犯了同样的错误,即在规范中没有标签df = pd.read_csv('/Documents/Melbourne_housing_FULL.csv') given:when:。然后偶然发现了这个问题,以找到Steinar的评论。