With all due respect to simendsjo, the fact that all tests should be independent of each other is a dogmatic approach that has many exceptions.
Return to the original question: 1) use dependent methods and 2) save the intermediate result in the field (TestNG does not recreate your instances from scratch, so the field will save its value).
for example
private int mResult; @Test public void f1() { mResult = ... } @Test(dependsOnMethods = "f1") public void f2() { // use mResult }
Cedric beust
source share