http://www.cs.ox.ac.uk/chaste/
Session 2 - What tests are
and how to use them
James Osborne
Introduction
• What is a test?• Test driven development • Tests in Chaste• CxxTest• Simulations?
What is a test?
• Check code does it do what it should?• Member variable updated correctly• ODE solved correctly • Simulation checked against stored result
– to ensure nothing changes• Two types of test• Unit testing – testing individual subunits• Acceptance test – code has required
functionality
Test driven
development
• From eXtreme Programming• Test-driven development cycle
Add a test
Run the automated
tests
Write some code
Run all tests and see if the new one fails
Refactor code
Fail
Pass
If tests pass
Testing in Chaste
• Every line of code is covered by a test • Tests run after every commit and overnight
(including memory and coverage testing) https://chaste.cs.ox.ac.uk/tests.py
• Tests are stored in the “test” folders• Use CxxTest…
CxxTest
• Doesn’t use a main method like normal C++• Write .hpp files (Classes)• Subclass of CxxTest::TestSuite• Public methods are the tests
• CxxTest turns this in to executable – tells you whether tests pass – you will see this in tutorial
CxxTest example
#include <CxxTest/TestSuite.h>
class MyFirstTestSuite: public CxxTest::TestSuite {public:
void TestSomething(){
TS_ASSERT_EQUALS(1+1,2);}
void TestSomethingElse(){
TS_ASSERT_DELTA(1,1.001,0.1);}
};
http://cxxtest.sourceforge.net/cxxtest/doc/guide.html
Chaste testing
infastructure
• Online https://chaste.cs.ox.ac.uk/tests.py• Continuous • Nightly • Coverage • Parallel
• Local version • see tutorial
Simulations as tests
• Why should you care about tests?• Every simulation in Chaste is a test…• … don’t write simulations, write tests• Use the tests to learn about functionality• If there is some functionality there will
have to be a test of it (coverage)
Writing tests
After lunch: • Log onto machine in 379 – pick wisely!• make sure it’s thee correct username as
Chaste (and your code) will be stored locally
• Go to “CellBasedWorkshopSession3”• Set up machine as per instructions in
Exercise 1• Go through “WritingTests” user tutorial
(Exercise 2)