【问题标题】:Unable to run spock tests with maven intellij无法使用 maven intellij 运行 spock 测试
【发布时间】:2016-06-09 20:22:16
【问题描述】:

我正在尝试使用 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 库能够在模块设置的依赖项选项卡中看到它们

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>

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

【问题讨论】:

  • 不,class 应该没问题
  • 你用的是什么版本的junit?
  • 你的文件夹是否设置为项目结构下的测试文件夹?我经常必须在那里添加然后删除我的测试,以便 intellij 再次找到它们。
  • @HankD 我正在使用junit 4
  • 看起来您在 'given:'、'when:'、'then:' 中缺少了 ':'。

标签: java maven intellij-idea spock


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-28
    • 2014-09-30
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    相关资源
    最近更新 更多