Getting the list of test case variables, from a Test Case, programmatically


Let’s say that you are testing a part of a system, that requires the test case to happen in multiple parts. For example, in my job, I have a test case that require me to:

  • create a test medical practice, complete with members
  • wait several days to pay invoices of all members
  • wait some more days to check pay out to the physician

You create the steps for the test cases, but then how do you remind yourself/fellow test devs to run the test case for the next step? You have two real options:

  • create Google Calendar event (or something similar) for the task manually, or…
  • create that same Google Calendar event programmatically

This is good, however, what to do if your test case steps have variables ? For example, what if they take npiNumbers, practiceProfiles, … , that you(r fellow test devs) need to run and validate the test case results? How do you get those programmatically?


Every Test Case Script has Binding, which then has Map<String, Object> variables. Hence, you could just say, in the Test Case itself:


to get the dictionary of test case variables. This will, as of the time of this post, only get the Test Case Variables!

Testing it out

Let’s create a Test Case, call it Test Case Variables, with the following test case variables:

Let’s then implement that test case to be:

import com.signaturemd.models.practice.PracticeModel

import groovy.transform.Field

final String tmpVar = "temp variable"

PracticeModel model = new PracticeModel()

String field = "field variable"

assert this.binding.variables == [ 
	('a') : 0,
	('b') : 1,

Run it, and you should see that this test case passes.


Thank you for such a great sharing. Keep going @mwarren04011990