LoginSignup
3
1

More than 5 years have passed since last update.

Spring boot 1.4.2でSpock1.1rc3でテストをする

Posted at

まだrcみたいでいろいろハマったのでメモ。
意外とspring boot + spock + gradle の組み合わせの記事がない。

build.gradle

groovyのプラグインとspock関係の依存を追加。
どうもSpring Boot 1.4.2の新しいアノテーションは、Spock1.1じゃないと対応してないらしいので、しょうがないのでrc版を使う。

以下の記事を参考
http://qiita.com/AHA_oretama/items/55bbde42cfa4bdbf50a0

build.groovy
plugins {
    id 'org.springframework.boot' version '1.4.2.RELEASE'
    id 'java'
    id 'groovy'
}

dependencies {
    compile "org.codehaus.groovy:groovy-all:2.4.1"
    testCompile "org.spockframework:spock-core:1.1-groovy-2.4-rc-3"
    testCompile "org.spockframework:spock-spring:1.1-groovy-2.4-rc-3"
}

テストコード

本当は、@SpringBootTestだけで良いっぽいのだけど、なぜか@ContextConfigurationを追加しないと動かなかった。

SpockTest.groovy
package hello

import org.springframework.test.context.ContextConfiguration
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.beans.factory.annotation.Autowired

import spock.lang.Specification
import spock.lang.Unroll

@ContextConfiguration
@SpringBootTest
public class SpockTest extends Specification {

  def "はじめましてSpock"() {
    expect:
      1 > 0
  }
}

以下の記事を参考
http://groovy-coder.com/?p=111

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1