I am converting a JMeter TestPlan into nUnit using RestSharp to consume API calls. My goal is to merge these tests into my visual studio project solution. My problem is, many of the API calls in the JMeter's Test Plan are extracting key/values from their JSON response which are then used in subsequent test's requests. My question is, is it possible in nUnit/RestSharp to define variables from a test's response that can be used in subsequent tests within a [TestFixture]? Or will these variables have to be redefined under every [Test]?
Use an [Order(n)]
attribute to run the tests in order, and I'd just use a private object to store the variables between tests. So something like:
[TestFixture]
public class Tests
{
private int valueBeingPassed;
[OneTimeSetUp]
public void Setup()
{
valueBeingPassed = 1;
}
[Test, Order(1)]
public void Test1()
{
valueBeingPassed += 2;
Assert.AreEqual(valueBeingPassed, 3);
}
[Test, Order(2)]
public void Test2()
{
var doubleValue = valueBeingPassed * 2;
Assert.AreEqual(doubleValue, 6);
}
}