Kurt Nørmark ©
Department of Computer Science, Aalborg University, Denmark
Abstract Previous lecture Next lecture Index References Contents | This lecture is about test of object-oriented programs. |
Program Testing in General |
Introduction to Program Testing Slide Annotated slide Contents Index References Textbook |
|
|
|
Overview of Program Testing Slide Annotated slide Contents Index References Textbook |
|
Testability Slide Annotated slide Contents Index References Textbook |
|
|
|
Test Utopia Slide Annotated slide Contents Index References Textbook |
|
The concept total test: A total test is a combinatorial complete test of all possible paths through a program |
|
|
From Program Test to Program Proof Slide Annotated slide Contents Index References Textbook |
|
|
|
White Box Testing |
White box testing Slide Annotated slide Contents Index References Textbook |
|
|
|
|
Basis Path Testing Slide Annotated slide Contents Index References Textbook |
|
The concept path: A path through a program unit is a sequence of commands and conditions that starts at program entry and ends at program exit | ||
The concept independent path: An independent path is path that adds at least one new command or condition relative to already identified independent paths |
|
Cyclomatic Complexity - flow chart Slide Annotated slide Contents Index References Textbook |
Program: A method P - emphasizing the program flow inside P. |
|
Figure. The flow chart for the program unit P |
Cyclomatic Complexity - flow graph Slide Annotated slide Contents Index References Textbook |
|
Figure. The accompanying flow chart for the program unit P |
Table. |
|
Cyclomatic Complexity - Metric and Test Cases Slide Annotated slide Contents Index References Textbook |
|
|
Exercise 14.2. Cyclomatic complexity of GCD | Find the cyclomatic complexity of Euclid's, gcd, function in this C program. If possible, find test cases that allow you to test each independent path of the gcd function. Independent paths are defined here in course material. How many test cases do you actually need to cover all source lines of the gcd function? |
Black Box Testing |
Black box testing Slide Annotated slide Contents Index References Textbook |
|
|
|
Input to a Black Box Test Slide Annotated slide Contents Index References Textbook |
|
The concept equivalence partitioning: An equivalence partitioning splits a set of input values in a (small) number of classes. It is hypothesized that it is sufficient to test the program unit on a single representative from each class |
|
Example of Equivalence Partitioning (1) Slide Annotated slide Contents Index References Textbook |
Program: The method signature SwapElements. |
|
|
|
Example of Equivalence Partitioning (2) Slide Annotated slide Contents Index References Textbook |
Program: The method signature FindMaxIndex. |
|
|
Regression testing Slide Annotated slide Contents Index References Textbook |
|
|
|
Unit Test of Object-oriented Programs |
Test Units Slide Annotated slide Contents Index References Textbook |
|
|
|
Unit Testing Slide Annotated slide Contents Index References Textbook |
|
A Unit Test example in C# (1) Slide Annotated slide Contents Index References Textbook |
|
|
Program: The class BankAccount. |
|
Program: The class BankAccountTest. |
|
Program: Compilation and execution. |
|
Figure. A screenshot of NUnit - all tests are successful |
A Unit Test example in C# (2) Slide Annotated slide Contents Index References Textbook |
|
Program: The class BankAccount - with an error. |
|
Program: The class BankAccountTest - same as before. |
|
Figure. A screenshot of NUnit - some tests fail |
NUnit for C# Slide Annotated slide Contents Index References Textbook |
|
|
Exercise 14.4. Install Nunit | Download and install the latest stable version Nunit from www.nunit.org on your computer. If you have not already done so, consult the basic information about NUnit on the accompanying slide. More specifically, for Windows users, goto the NUnit download page and download the most recent stable version of NUNIT for .NET 2.0. As of February 2010 this is the NUnit-2.5.3.9345.msi file (a Windows installer file). You can also get this file directly from here. Mono users on Linux probably already have an installation of NUnit. According to the NUnit documentation, Mono 1.0 through Mono 1.9 include NUnit 2.2. Try calling the NUnit console runner named nunit-console from your shell. Please be aware of the version you are running. The newest stable version of NUnit is 2.5.3 (as of February 2010). Mono users are recommended to use version 2.4.8, however. See also the release notes. Next, consult the NUnit documentation. Pay attention to the menu to the right. In particular the CORE FEATURES documentation of Assertions and Attributes. |
Exercise 14.4. Give Nunit a Try | This exercise is guided tour in using NUnit (version 2.5.3) together with Visual C# 2008 Express on Windows. The exercise will help set up the BankAccount test, which we have seen on an earlier slide page in this material. If you use C# via another IDE, or on a non-Windows platform, you should not follow this guide. We will assume that you already have installed Nunit and that you use Visual C# 2008 Express. Start Visual C# 2008 Express. Use File > New Project... and make a Class Library project. In the Solution Explorer (usually at the far right of you screen) right click References, and do Add Reference.... Select and add nunit.framework (version 2.5.3) from the list. (The list may be long, so be careful to select the right entry). Use Project > Add Class... to add the BankAccount class. (Do copy and paste from the BankAccount class of this material). Paste the BankAccountTest class instead of Class1, which was made automatically by Visual C# 2008 Express. Now build your library application: Use F6 as usual. "Build succeeded" is expected. Do File > Save All. Notice the Location of you project. On a piece of paper (or in a text editor) notice the full file path to your Visual C# 2008 project. You can also get information about your project locations via the C# 2008 Express menu entry Tools > Options..., 'Projects and Solutions'. Start NUnit 2.5.3 - for instance via the Icon on your desktop or via the Windows start menu. In NUnit use Tools -> Settings... and check the 'Enable Visual Studio Support' in the window which appears. You find the check box in IDE Support > Visual Studio. (This is most likely the default setting in NUNIT 2.5.3). In NUnit use File > Open Project, and select the dll named after your project. The file is most likely located in the Bin/Debug branch of your project directory (as you should have noticed above). Activate the Run button in NUnit. You should see 'green light'. Introduce an run-time error in BankAccount class. Is the error revealed in unit test? If you managed to get to here you should be able to use NUnit on your own stuff. Congratulations. |
NUnit Attributes Slide Annotated slide Contents Index References Textbook |
|
|
|
NUnit Assertions Slide Annotated slide Contents Index References Textbook |
|
|
Unit Test Concepts Slide Annotated slide Contents Index References Textbook |
|
|
|
|
Another Unit Test example in C# Slide Annotated slide Contents Index References Textbook |
|
Program: The class Set<T>. |
|
Program: The class SetTest. |
|
Exercise 14.5. Test of class Set | In a previous exercise we have implemented the operations intersection, union, and set difference in class Set<T>. In continuation of class SetTest, perform unit tests of the intersection, union, and set difference operations. The natural starting point is your solution to the previous exercise. You can also chose to test my solution. |
Unit test of struct Interval Slide Annotated slide Contents Index References |
|
Program: A slightly revised version of the Interval struct - with an error. |
|
Program: An initial test suite of struct Interval. |
|
Exercise 14.6. Unit test of struct Interval | You are given a version of struct Interval, which we have worked with in an earlier exercise. You are also given a partial test suite of struct Interval. In the given Interval test suite all tests should be successful. (You may have to adjust the full qualified names of exceptions in the ExpectedException attributes, however). Please check for yourself that all tests pass successfully. Add a test of the indexer and a test of the OverlapWith method. Both are members of type Interval, as given above. In the version of struct Interval from above there is at least one error in either the indexer or the OverlapWith method. You should be able to reveal the error from your tests! Please correct the error when you have found it. Carry out a regression test. There are several overloaded operators in struct Interval. I have only made a test of the + operator. If time allows, add some additional tests of the non-tested Interval operators. Finally, discuss the expected coverage of my Interval test cases together with your additional Interval test cases. |
Test Scaffolding Slide Annotated slide Contents Index References Textbook |
|
Test scaffolding |
|
|
The Background and Context of Unit Testing Slide Annotated slide Contents Index References Textbook |
|
|
|
Test of Object-oriented programs Slide Annotated slide Contents Index References Textbook |
|
|
Test Driven Development Slide Annotated slide Contents Index References Textbook |
|
|
Unit Test Recommendation Slide Annotated slide Contents Index References Textbook |
|
Test Recommendations in your Project Slide Annotated slide Contents Index References |
|
|
Collected references Contents Index |
|
Chapter 14: Test of Object-oriented Programs
Course home Author home About producing this web Previous lecture (top) Next lecture (top) Previous lecture (bund) Next lecture (bund)
Generated: February 7, 2011, 12:22:50