![Page 1: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/1.jpg)
Chapter 8
Testing the Programs
![Page 2: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/2.jpg)
Chapter 8 Learning Objectives Be able to …
Define different types of faults and how to classify them
Define the purpose of testing
![Page 3: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/3.jpg)
Discussion Questions
What are some different types of program faults?
What is the difference between a program fault versus a program failure?
![Page 4: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/4.jpg)
Discussion Questions
Why do we test for program faults?
Who does the testing?
![Page 5: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/5.jpg)
Chapter 8 Learning Objectives Be able to …
Describe unit testing
Describe integration testing
Explain the difference between them
![Page 6: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/6.jpg)
Unit Testing unit testing is a procedure used to validate
that individual units of source code are working properly
A unit is the smallest testable part of an application In procedural programming a unit is a function,
procedure, subroutine, etc. In object-oriented programming, a unit is a method
The goal is to show that the individual parts are correct
![Page 7: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/7.jpg)
Integration Testing
B
A
E D C
F G I H K J
Top-down testingBottom-up testingSandwich testingBig-bang testing
![Page 8: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/8.jpg)
Discussion Question
What are some differences between integration testing of
object-oriented programs versus
procedural programs?
![Page 9: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/9.jpg)
OO Integration Testing Strategies
Thread-based testing: integrates classes required to respond to event
Use-based testing: integrates classes required by one use case
Cluster testing: integrates classes required to demonstrate one collaboration
![Page 10: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/10.jpg)
Discussion Question
How do we know when we can stop testing?
![Page 11: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/11.jpg)
Unit Testing with xUnit Test fixture : a class that contains one or more
test methods Test method : a method that executes a
specific test Test runner : an application that finds and
executes test methods on test fixtures Assertion : a Boolean expression that
describes what must be true when some action has been executed
![Page 12: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/12.jpg)
public class Account{ private double balance = 0.0; public Account(double b) { balance = b; } public double Balance { get { return balance; } }
public void Withdraw(double amount) { if (balance >= amount) balance -= amount; } public void Deposit(double amount) { // TO DO }}
Class to be unit tested
![Page 13: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/13.jpg)
[TestClass()] public class AccountTest {
...
[TestMethod()] public void WithdrawTestWithSufficientFunds() { Account acct = new Account(100.0); acct.Withdraw(50.00); Assert.AreEqual(50.0, acct.Balance); }
[TestMethod()] public void WithdrawTestWithInsufficientFunds() { Account acct = new Account(100.0); acct.Withdraw(150.00); Assert.AreEqual(100.0, acct.Balance); }
Test Fixture
![Page 14: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/14.jpg)
Test Runner
![Page 15: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/15.jpg)
Test-Driven Development
Never write a single line of code unless you have a failing automated test
Refactor to eliminate duplication
![Page 16: Chapter 8 Testing the Programs. Chapter 8 Learning Objectives Be able to … Define different types of faults and how to classify them Define the purpose](https://reader036.vdocument.in/reader036/viewer/2022062322/56649f465503460f94c689c2/html5/thumbnails/16.jpg)
Red/Green/Refactor1. Write the test code2. Compile the test code
(It should fail because you haven’t implemented anything yet.)
3. Implement just enough to compile.4. Run the test and see it fail.5. Implement just enough to make the test pass.6. Run the test and see it pass.7. Refactor for clarity and to eliminate duplication.8. Repeat from the top.