LoginSignup
1
0

More than 5 years have passed since last update.

Eclipseを使ったgeb環境構築 その2 前編

Posted at

今回はbuild.gradleを編集して、サンプルプログラムが実行できるところまで書こうと思ったけど
テスト実行に失敗してしまったので前編、後編に分けて書こうかと思います。

build.gradleの編集

前回eclipseでGradle Projectを新規作成してみました。

その時出来上がったbuild.gradleがこちら

build.gradle
apply plugin: 'java'

repositories {
    jcenter()
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.21'
    testCompile 'junit:junit:4.12'
}

まずはgroovy環境に修正〜。

build.gradle

//デフォルトだとjavaになっているのでgroovyに修正
apply plugin: 'groovy'

repositories {
    jcenter()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.1'
    testCompile 'junit:junit:4.12'
}

っでspock用に書き直したのが下記。
いちよう先にseleniumのドライバも入れておきます。

build.gradle

//デフォルトだとjavaになっているのでgroovyに修正
apply plugin: 'groovy'

repositories {
    jcenter()
}

//デフォルトエンコーディングはUTF-8指定で。
def defaultEncoding = 'UTF-8'
compileJava {
    options.encoding = defaultEncoding
}
compileTestJava {
    options.encoding = defaultEncoding
}
compileGroovy {
    groovyOptions.encoding = defaultEncoding
    options.encoding = defaultEncoding
}
compileTestGroovy {
    groovyOptions.encoding = defaultEncoding
    options.encoding = defaultEncoding
}


dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.4.1'

    testCompile "org.gebish:geb-spock:0.12.2"
    testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
    testCompile "org.seleniumhq.selenium:selenium-chrome-driver:2.37.1"
    testRuntime "org.seleniumhq.selenium:selenium-support:2.37.1"

}

テストの実行

さっそくテストしてみたいと思います。
ちなみにサンプルコードはeclipseでプロジェクト作成した時に自動的にサンプルコードが作成されるので、それを使ってみます。
image

かんたんなテストコードをgroovyで作成してRunしてみます。
「src/test/groovy」ディレクトリを作成しテストコードを書きます。
※ビルドパスの設定を忘れずに!

image

まずはjunitから実行してみましょう。

ん!!なんだこのエラー・・・。

Caused by: groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-all is loaded in version 2.4.1 and you are trying to load version 2.4.7
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl$DefaultModuleListener.onModule(MetaClassRegistryImpl.java:509)
    at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromProperties(ExtensionModuleScanner.java:77)
    at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanExtensionModuleFromMetaInf(ExtensionModuleScanner.java:71)
    at org.codehaus.groovy.runtime.m12n.ExtensionModuleScanner.scanClasspathModules(ExtensionModuleScanner.java:53)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:110)
    at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:71)
    at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:33)
    ... 19 more

ん〜。なんかバージョンの競合が発生している模様。。。

また時間があるときに調査・記事更新します!!

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