I have solved a topCoder problem for which all the tests pass when I run them on their own. Nonetheless when I run the whole test class some of them fail. Could you, please,
You are sharing a single instance of the class under test across all tests. I'd remove the initial assignment and add this:
private GameOfStones gameOfStones; // Don't create an instance here
@BeforeMethod
public void setUp() {
gameOfStones = new GameOfStones();
}
... which will use a new instance for each test. Good practice would also be to clean up after each test:
@AfterMethod
public void tearDown() {
gameOfStones = null;
}
In the example given here, fixing the class scoped variable causing the problem to be method scoped instead would also fix the issue, but as the software under test gets more complex it's good to start doing proper test set up and tear down.