Download T2 : Automated Testing Tool for Java User Manual

Transcript
62
CHAPTER 11. DEALING WITH PERSISTENT COMPONENTS
try { fw.write(":" + temperature) ; fw.flush() ; }
catch (Exception e) { }
}
}
Running T2 to test this class raises a problem. Values appended by a sequence to mylog will be
carried over to the next sequence; thus breaking T2’s non-inteference assumption.
This problem can be solved by reseting the content mylog to some fix value whenever we start
a new sequence. This makes sure that a sequence won’t influence the next ones through this file.
We do this by subclassing Pool, and implement our reset procedure in its reset method:
public class MyPool {
public MyPool() { super() ; }
public void reset() {
// This will do to empty the file:
try { new FileWriter("mylog") ; }
catch (Exception e) { }
super.reset() ;
}
}
Now we only need to pass the above class MyPool to T2 to test Simple, which we can do it like
this:
java -ea -cp TT.jar Sequenic.T2.Main Thermometer --pool=MyPool