【问题标题】:How to run multiple test suites in another test suite with geb如何使用 geb 在另一个测试套件中运行多个测试套件
【发布时间】:2018-03-05 10:43:38
【问题描述】:

我想运行我所有的测试套件。我想在一个名为 Allrun 的测试套件中调用测试套件。 我可以在另一个测试套件中调用测试套件吗?我正在寻找这样的东西:

class Myfirst extends GebReportingSpec {

 def myfunction(){
    when:''
    at mypage1

    and:''
     element1.text() == "mytext1"
  }
}

class Mysecond extends GebReportingSpec {

  def mysecondFunction() {
    when:''
    at mypage2

    and:''
     element2.text() == "mytext2"

   }

 }

 class AlltestSuites extends GebReportingSpec {
     Myfirst myfirst = new Myfirst ()
     Mysecond  mysecond = new Mysecond ()


    def allrun(){
          myfirst.myfunction() 
          mysecond.mysecondFunction()
      }


  }

我该怎么做?有没有人有想法

【问题讨论】:

  • 您需要按特定顺序吗?或者只是运行所有*Spec
  • 我不明白这个问题。 Maven 和/或您的 IDE 应该会自动为您执行此操作。

标签: testing groovy automated-tests spock geb


【解决方案1】:

您可以创建如下所示的 AllRun.groovy 文件,以按指定顺序运行所有类文件 [Myfirst.class、Mysecond.class 等]。

package geb.groovy

import org.junit.runner.RunWith
import org.junit.runners.Suite
import geb.groovy.scripts.Myfirst
import geb.groovy.scripts.Mysecond


@RunWith(Suite.class)
@Suite.SuiteClasses([Myfirst.class, Mysecond.class])
class CustomJUnitSpecRunner {
}

并且在 build.gradle systemProperties System.properties 中,排除个别的 Myfirst.class、Mysecond.class 文件。这样它们就只通过 AllRun 文件运行一次。

include 'geb/groovy/AllRun/**'
exclude 'geb/groovy/scripts/**'

【讨论】:

    【解决方案2】:

    可以使用以下命令运行规格组,其中packagesrc/test/groovy/specs 下的目录:

    mvn test -Dtest=specs.package.*
    

    如果您依赖规范以特定顺序运行,我会重新考虑您的方法。如果您需要某种状态的数据,请使用 setup() 和 setupSpec() 方法。还可以考虑在单个规范中运行相关测试,并使用 @Stepwise 注释按照编写顺序运行这些测试。

    @Stepwise
    class MyStepWiseTest extends GebReportingSpec {
    
     def myfunction(){
        when:''
        at mypage1
    
        and:''
         element1.text() == "mytext1"
      }
    
      def mysecondFunction() {
        when:''
        at mypage2
    
        and:''
         element2.text() == "mytext2"
    
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-03
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      相关资源
      最近更新 更多