Forum Discussion

M_McDonald's avatar
M_McDonald
Super Contributor
15 years ago

Run TestCase setup only if not in a Load Test

Hi -

I want to be able to generate an identifier that would be shared across all threads in a load test and also be available if the test case was being run standalone. Any suggestions? Is there a way to detect if my TestCase is being executed by a loadtest runner or not?

Thanks.

- Michael

2 Replies

  • Hello,

    You should be able to use the DataGen TestStep for this. Create a DataGen TestStep in your TestCase, and add a Property to it with the Script type. Set the Mode to STEP and make sure it's set to Shared. Use the following Script:


    def useContext = context.LoadTestContext ?: context
    useContext.myid ?: ( useContext.myid = Math.random() )


    Basically, it will get either the LoadTestRunContext if you're running a LoadTest, or the regular TestRunContext if you're running a TestCase. It will then check if the context has a "myid" variable, and either return it, or generate a new value and set and return that. You can of course replace Math.random() with some other function to generate a more suitable identifier:


    def generateId() {
    //Generate and return a unique ID.
    }

    def useContext = context.LoadTestContext ?: context
    useContext.myid ?: ( useContext.myid = generateId() )


    Hope this helps!

    Regards,
    Dain
    eviware.com