1

Problem statement: How to execute a function at the end of all specification files have been executed using spock framework.

Explantion: I am using geb-spock framework for automation.

I have few specification files. I want to run a function after all specification files have been executed.

I want something like AfterSuite in TestNG. How can i get the feature of AfterSuite in spock. cleanupSpec will be called after every specification file is executed.

Thanks, Debasish

3 Answers3

1

The simple answer is: no. There's nothing like before or after suite methods in spock since spock is JUnit based and JUnit does not handle such methods. If you się tool like maven or gradle maybe you can use task's lifecycle methods.

Opal
  • 81,889
  • 28
  • 189
  • 210
0

You can use the JUnit 4 SuiteRunner Look at this answer

@RunWith(Suite.class)
@SuiteClasses({ TestSpec.class, TestSpec.class })
public class CompleteTestSuite {

    @BeforeClass 
    public static void setUpClass() {      
        System.out.println("Master setup");

    }

    @AfterClass public static void tearDownClass() { 
        System.out.println("Master tearDown");
    }

}
Community
  • 1
  • 1
twinj
  • 2,009
  • 18
  • 10
0

If you are using build tool as for example Gradle you may wire it on a build configuration level after tests are finished.

topr
  • 4,482
  • 3
  • 28
  • 35