Download presentation
Presentation is loading. Please wait.
Published byCollin Lane Modified over 9 years ago
1
Unit Testing Maintaining Quality
2
How do you test? Testing to date…
3
Testing Large Systems Old school: – Programmers write parts of code Maybe check tricky bits – Someone tries to build whole project Sort out incompatibilities – Hand it off to testing This job is awful
4
Testing Goals Principles: – Tests should cover as much code as possible – Tests should be run after any significant change – Tests should not clutter up core source
5
Testing Goals Principles: – Tests should cover as much code as possible – Tests should be run after any significant change – Tests should not clutter up core source So: – Tests better be easy to write – Tests better be easy to run – Tests better exist outside normal structure
6
Unit Tests Unit Test : – Tests one module of code – Automated – Run after any changes to code
7
Other Testing Still need: – Integration testing But easier – UI testing But just testing UI code
8
Doing Unit Testing Basic idea: – Write functions TESTS to test your code Tests can be passed or failed
9
What does it actually look like? Base project – Normal application – Header file(s) for classes –.cpp file(s) for classes – main file with "real" program
10
What does it actually look like? Test project – Special header with test stuff Included in test files only – One.cpp file to test each class – New main file to run tests
11
Building / Running Activate / Build / Run standard project Normal program
12
Building / Running Activate / Build / Run test project Run unit tests
13
Details catch.hpp Don't touch
14
Details mainTester.cpp – Has main function Runs tests automatically – Can be configured
15
Details CLASSXTESTER.cpp – Includes class.h / catch.hpp – Has TEST_CASEs Expression that must be true Machine name - must be unique Description
16
Details CLASSXTESTER.cpp – Includes class.h / catch.hpp – Has TEST_CASEs Expression that must be true Machine name - must be unique Description
17
== doubles Not OK to compare doubles with ==
18
== doubles Can write your own function to test for approximate equality:
19
== doubles But Catch includes macro to simplify: – Approx( value )
20
Details Pattern – Make an object – Call functions to be tested – REQUIRE correct data Must use public methods to access
21
What Do I Test Test public interface Test every method/construct except… – Trivial one liners: Usually don't directly test getXXX() – IO code: Hard to do from testing frameworks
22
Features Test Mapping Focus on one features per test Some features may need multiple tests: connect.setURL("http://www.google.com") connect.setURL("www.google.com") connect.setURL("ftp://chemeketa.edu") isPrime(3) isPrime(4)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.