I have framework that has been written in Groovy, Spock and JUnit. Are there any way for getting variable from CreateResource class (after its execution) in GetResource class?

public class SimpleTestSuit {}

For example, I would like to book hotel in CreateResources class and will get booking number in GetResources class? In the same time, I want to save order of execution.

Maybe, there is any an approach for that. Either using some context, or anything else.

1 Answer 1


Sound like you just need to set a publicly accessible variable (or an object with a getter/setter) in the GetResource class, from your CreateResource class. This approach works in non-parallel runs.

In JUnit it looks something like this:

public static string hotelReservation; // in the Test class or some other class that you reference

public void MyTest001() {
    //... perform actions
    hotelReservation = someElement.text;

public void MyTest002() {
    // do something with hotelReservation variable
  • Thank you for answer, but I mean other. I have two test scenarios, due this I would like to run first scenario (book hotel) and after second in which are using resource (booking number) from first. It's separated tests.
    – J. Brown
    May 8, 2017 at 12:59
  • In my example, the first test sets the hotelReservation (booking number) and the second uses it . If the tests are in different classes, put the booking number in a separate class and make sure its accessible by the test classes.
    – kirbycope
    May 8, 2017 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.