Forum Discussion

rajs2020's avatar
rajs2020
Frequent Contributor
4 years ago

Run a test before other tests in a suite?

I want to create a test suite in which the 1st test case supplies test data to the subsequent test cases via its custom properties. I want the first test case to run only once before any other test case in the suite. It should run only once when I run all the tests in the suite, or when I run only one test in the suite. How do I do this in ReadyAPI? Is it a good idea to implement my test data setup like this?

 

PS - This is similar to TestNg @BeforSuite or @BeforeClass annotations.

  • rajs2020 : You can create setup script for the same. It will get executed only once and load all your data into the custom properties and you can use the data in subsequent test cases.

     

    • rajs2020's avatar
      rajs2020
      Frequent Contributor

      HimanshuTayal, nmrao - Could you please point me to the documentation for suite and test level setup? Does the suite level setup run only if you run the entire suite or does it also run if you run only one test ? I require both.

      • richie's avatar
        richie
        Community Hero
        Hey rajs2020,

        Using the approach i outlined would just be at testsuite level.

        However you could alter my approach so it runs at testcase level (as you want) instead by not bothering adding an inital single "setup" testcase (that contains "Run testcase" step that executes the disabled "setup" testsuite) in the functional testsuites. Instead you would add the "Run testcase" step as the first step in each of the testcases in the functional testsuites.

        E.g.

        -Setup testsuite (disabled)
        --Generate access token testcase
        ---Generate token RESTstep
        ---Property Transfer (xfers the access token to project level property)

        -Functional testsuite (enabled)
        --Create new record testcase
        ---Run testcase teststep (executes Generate access token testcase)
        ---Create new record REST step (that sources access token from project level property)

        Using the above approach has the advantage that the "setup" testsuites arent executed by default until the functional testcases execute cos the setup testsuites are disabled. Also, having the Run testcase steps in each test or suite means that if the token expires before the end of the session it doesnt matter cos it is re-generated each time the testcase (suite) is run.

        The above approach is what nmrao showed me a while back and Ive been using this approach ever since.

        Ta

        Rich
  • nmrao's avatar
    nmrao
    Champion Level 3
    Hope you might aware of setup which is available at test case, suite and project levels. Can't you use that?

    • richie's avatar
      richie
      Community Hero
      Hey rajs2020,

      Im reiterating what Rao and Himanshu said. I have a number of disabled "setup" testsuites with steps to generate my environment specific variables (that get saved off as project level properties) and for esch functional testsuite i have a "setup" testcase (1st testcase in each functional testsuite) that uses the "Run testcase" step to execute the tests in the disabled "setup" testsuites to generate the latest versions of the dynamic data needed.
      My functional testcases call the needed properties from the project level properties.

      This is the approach i use in all my readyapi! projects now.

      Ta

      Rich