Can we pass a value generated in a test case to another test case as a input?

PRoshan

New member
Joined
Jun 26, 2020
Messages
3
Programming Experience
1-3
Hi All,

I have come across a situation where , in a test case , i will be creating a name which is going to be the input for the nexttest case.

In detail :

  1. Test case A : This test case is to schedule an audit... I have to schedule an audit by giving Unique " Audit name " each and every time.
Note : Audit name will be randomly generated with the help of script. ( I am not passing the" audit name" value from a data file or as a Global variable )
  1. Test Case B : In this test case... i need to map an audit to the auditor based on the "Audit name " created in the Test case A.
  2. I cannot call the "Test case A " in "Test case B " because "Close browser " is the last step in Test Case A. When the execution of A gets finished automatically the browser will close it stopping me from pass the " Audit name" from A to B.
I have so many scenarios like the above.
SO … I am in need of help from the community to resolve this.

Please help me out of this.

Let me know for further clarifications.
 
Test cases are supposed to be independent of each other. The idea being that if one one test is failing, the developer can just keep iterating on running that test until it succeeds. Once that works, then re-run the entire suite to make sure there are no regressions. And if the dev is really smart, they would see if they need to add one or more new tests to further exercise/test the issue that was uncovered by previously failing test.

As for your issue above, here is a low level tactical approach: you need to make your randomizer less random. E.g. instead of using the default Random class constructor that uses the current time as its seed, use the constructor that takes an explicit seed value. Seed the randomizer with an explicit value to get the same random name.

The bigger issue here though is that you are not following the A-A-A rules for writing a test. Each test should Arrange, do the Action, and then Assert that the action succeeded. What you are doing is expecting the other test to do the Arrange for you. Don't do that. Instead move the code that does the arrangement into the constructor of the test class (if you are using xUnit), or a setup method (if you are using NUnit or MSTest).
 
Back
Top Bottom