Grails 3.1.1 JUnit测试因无法理解的错误而失败

时间:2016-10-31 03:57:06

标签: grails gorm

即使应用程序本身运行良好,Grails域单元测试也不会运行。这是Grails自动插入的测试。我没有对它进行任何更改,但它没有运行,因为一个难以理解的错误而失败。

package com.grapevine.negotiator2

import grails.test.mixin.TestFor
import spock.lang.Specification
/**
  * See the API for {@link  grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(ProfileQuote)
class ProfileQuoteSpec extends Specification {

   def setup() {
   }

   def cleanup() {
   }

   void "test something"() {
    expect:"fix me"
        true == false
    }
}

这是错误

"C:\Program Files\Java\jdk1.8.0_101\bin\java" -ea -Didea.launcher.port=7533 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.3\bin" -Didea.junit.sm_runner -classpath C:\Users\jkramer\AppData\Local\Temp\classpath1.jar -Dfile.encoding=UTF-8 com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.grapevine.negotiator2.ProfileQuoteSpec
in application

java.lang.NoSuchMethodError: org.grails.datastore.gorm.GormEnhancer.<init>(Lorg/grails/datastore/mapping/core/Datastore;Lorg/springframework/transaction/PlatformTransactionManager;Z)V

at        grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomains(DomainClassUnitTestMixin.groovy:84)
at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:107)
at grails.test.mixin.domain.DomainClassUnitTestMixin.mockDomain(DomainClassUnitTestMixin.groovy:106)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:153)
at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at grails.test.runtime.TestRuntimeJunitAdapter$1$2.evaluate(TestRuntimeJunitAdapter.groovy:46)
at org.spockframework.runtime.extension.builtin.TestRuleInterceptor.intercept(TestRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:88)
at org.spockframework.runtime.extension.builtin.AbstractRuleInterceptor$1.evaluate(AbstractRuleInterceptor.java:37)
at grails.test.runtime.TestRuntimeJunitAdapter$3$4.evaluate(TestRuntimeJunitAdapter.groovy:73)
at org.spockframework.runtime.extension.builtin.ClassRuleInterceptor.intercept(ClassRuleInterceptor.java:38)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

处理以退出代码-1

结束

这是build.gradle:

   buildscript {
    ext {
        grailsVersion = project.grailsVersion
    }
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:3.1.2"  //$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
        classpath "org.grails.plugins:hibernate4:5.0.10"

    }
}

version "0.1"
group "com.grapevine.negotiator2"

apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"


ext {
    grailsVersion = project.grailsVersion
    gradleWrapperVersion = 2.2
}

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
}

dependencyManagement {
    imports {
        mavenBom "org.grails:grails-bom:$grailsVersion"
    }
    applyMavenExclusions false

}

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate4"
    compile "org.hibernate:hibernate-core:4.3.10.Final"
    compile "org.hibernate:hibernate-ehcache:4.3.10.Final"
    compile "org.grails.plugins:spring-security-core:3.1.1"
    compile "org.grails.plugins:spring-security-ui:3.0.0.M2"
    compile 'org.grails.plugins:mail:2.0.0.RC6'
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.8.2"
    runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
    compile 'org.grails:grails-datastore-core:5.0.4.RELEASE'
    compile 'org.grails:grails-datastore-gorm-support:5.0.4.RELEASE'
    compile 'org.grails:grails-datastore-gorm:5.0.4.RELEASE'
    compile 'org.grails:grails-datastore-simple:5.0.4.RELEASE'
    compile 'org.grails:grails-datastore-gorm-hibernate4:5.0.4.RELEASE'
    compile 'org.grails:grails-datastore-gorm-hibernate-core:5.0.4.RELEASE'
    //  https://repo.grails.org/grails/core/org/grails/grails-datastore-core/5.0.4.RELEASE
    //  grails-datastore-gorm-hibernate4-5.0.4.RELEASE.jar
}

assets {
    minifyJs = true
    minifyCss = true
}

这是域类:

    package com.grapevine.negotiator2

class ProfileQuote {

    int scale
    String quote

    String toString() {
        "$quote"
    }
    static constraints = {
        scale range: -5..5

    }
    static getQuote(double scale) {
        int scaleint = (int) Math.round(scale)
        def quotes = findAllByScale(scaleint)
        def numQuotes = quotes.size()
        def r = new Random()
        def i = r.nextInt(numQuotes-1)
        return quotes.get(i)

    }

}

0 个答案:

没有答案