session 2 -what tests are and how to use them€¦ · • acceptance test – code has required...

10
http://www.cs.ox.ac.uk/chaste/ Session 2 - What tests are and how to use them James Osborne

Upload: others

Post on 18-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

http://www.cs.ox.ac.uk/chaste/

Session 2 - What tests are

and how to use them

James Osborne

Page 2: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

Introduction

• What is a test?• Test driven development • Tests in Chaste• CxxTest• Simulations?

Page 3: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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

Page 4: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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

Page 5: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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…

Page 6: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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

Page 7: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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

Page 8: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

Chaste testing

infastructure

• Online https://chaste.cs.ox.ac.uk/tests.py• Continuous • Nightly • Coverage • Parallel

• Local version • see tutorial

Page 9: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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)

Page 10: Session 2 -What tests are and how to use them€¦ · • Acceptance test – code has required functionality. Test driven development • From eXtreme Programming • Test-driven

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)