首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >驱动程序:为什么我的测试运行两次?

驱动程序:为什么我的测试运行两次?
EN

Stack Overflow用户
提问于 2013-01-18 18:04:28
回答 2查看 1.3K关注 0票数 3

对不起,这些代码,但我不知道是什么使我的问题,所以就这样。

我将geb插件配置为使用JUnit运行功能测试。所以我在我的buildConfig.groovy

代码语言:javascript
复制
def seleniumVersion = "2.29.0"
def gebVersion = "0.7.0"

dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

    // runtime 'mysql:mysql-connector-java:5.1.5'

    provided('com.oracle:oracle:11.1.0.7.0')
    provided('com.oracle:i18n:10.2.0.5')


    test ("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion") {
        export = false
    }
    test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"){ 
        excludes "commons-io"
        export = false
    }
    test ("org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion") {
        export = false
    }

    test ("org.seleniumhq.selenium:selenium-support:$seleniumVersion") {
        export = false
    }
    test ("org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion") {
        export = false
    } 

    test ("org.codehaus.geb:geb-junit4:$gebVersion") {
        export = false
    }

}

plugins {
  build(":tomcat:$grailsVersion") {
  export = false
  excludes 'svn'
  }
  compile (":hibernate:$grailsVersion") {
  export = false
  excludes 'svn'
  }

  build (":release:2.0.0") {
  excludes 'commons-io','http-builder'
  export = false
  }

   compile(":spring-security-core:1.2.7.3") { excludes 'svn' }
   compile(":spring-security-ldap:1.0.6")

   compile (":remote-control:1.3") {
  export = false
   }

   test(":geb:$gebVersion") {
     export = false
   }
}

在我的conf文件夹中有一个GebConfig.groovy

代码语言:javascript
复制
driver = {
//def driver = new HtmlUnitDriver()
//driver.javascriptEnabled = true
//driver
def driver = new FirefoxDriver()
driver
} 

environments {
   // run as “grails -Dgeb.env=chrome test-app”
   // See: http://code.google.com/p/selenium/wiki/ChromeDriver
   chrome {
     driver = { new ChromeDriver() }
   }

   // run as “grails -Dgeb.env=firefox test-app”
   // See: http://code.google.com/p/selenium/wiki/FirefoxDriver
   firefox {
    driver = { new FirefoxDriver() }
  }
}

我有一个登录的功能测试:

代码语言:javascript
复制
class LoginTests extends GebReportingTest {


    @Test
    void login() {
        to LoginPage
        at LoginPage

        username = "SERGIO"
        password = "SERGIO"

        loginButton.click()

        assert at(IndexPage)

        link.click()

    }

}

这是我的两页:

代码语言:javascript
复制
class LoginPage extends Page {

    static url = "login/auth"

    static at = {
        title ==~ /Efetuar Login/
    }

    static content = {
        loginForm { $("form", id: "loginForm") }
        username { $("input", type:"text", id:"username") }
        password { $("input", type:"password", id:"password") }
        loginButton{ $("input", type:"submit", id:"submit") }
    }

}

class IndexPage extends Page {

    static at = {
        title ==~ /Security Service Index View/
    }

    static content = {
        description { $('h1') }
        link { $('a') } 
    }

}

出于某种原因,我的功能测试运行了两次,并且不管我如何启动它:

代码语言:javascript
复制
grails test-app :functional

grails test-app -functional
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-22 06:34:25

看起来Geb插件与Grails2.3.x并不完全兼容。出于某种原因,在升级到Geb插件0.9.2之后,测试会被执行两次。

我认为这个问题与https://jira.grails.org/browse/GRAILS-10552和作为https://jira.grails.org/browse/GRAILS-6352的一部分所做的更改有关。

在Grails 2.3.x+中,GrailsSpecTestType同时负责Junit和Spock测试:https://github.com/grails/grails-core/blob/bce298f0/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy#L33

看起来,Geb插件正在将不推荐的JUnit4GrailsTestType添加到执行中:Events.groovy#L60-L67

这就是为什么功能测试两次被执行的原因。

这就是我如何在Geb 0.9.2 / 0.9.3版本中解决问题的方法。

代码语言:javascript
复制
grails test-app functional:spock

看起来Geb版本0.9.1没有执行两次测试。

这种差异似乎是由以下提交引起的:https://github.com/geb/geb/commit/9c71e820

您还应该注意,您不应该在Grails2.3.x/2.4.x中安装Spock插件。

票数 3
EN

Stack Overflow用户

发布于 2013-01-24 14:49:43

嗨,Ruby上的Selenium WebDriver并不多见,但是您似乎要启动两次火狐,测试在两个实例中运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14404892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档