Title: Unit Testing
1Unit Testing
- What, Why, When, Where, Who and How.
2What is Unit Testing?
- Also know as Box Testing.
- Testing bits or units of code without running
the entire application. - This could be a object, a collection of objects,
a library of procedures or functions or any other
unit of code that can be tested independent
from the rest of the application.
3Why should I do Unit Testing?
- To avoid having to compile and run the entire
application just to check a single function. - This reduces the cycle time between writing code
and testing it. The shorter this cycle the better
able you are to test specific functionality.
4Why should I do Unit Testing?
- Allows stress testing of code that may not be
feasible by running the application. - Many applications are too complex to fully test
in the development phase. Many multi-user
applications are shipped to clients without
testing the level of use that will happen at the
at the client site. - Unit testing allows you to stress test individual
sections of code in ways that a single user
cannot.
5Why should I do Unit Testing?
- Have users or testers with domain knowledge do
testing of particular functionality before it is
incorporated into the main code. - In many cases even very good specifications are
not enough to write completely accurate code. If
you can identify individuals that have detailed
knowledge of a certain functionality, then you
can write unit tests that will allow them to test
that functionality before the code in
incorporated into the application.
6Why should I do Unit Testing?
- Automated testing.
- Adding tests to the framework as you write code
allows you to quickly, and repeatedly test code. - There are a number of frameworks for generating
automated tests.
7What should I Unit Test?
- Test objects.
- Test connections.
- Test forms.
- Test anything you can think of.
8When should I do Unit Testing?
9When should I do Unit Testing?
- Before you start to write code!!
- As you write code!!
- Any other time you can!!
10When should I do Unit Testing?
- Think of tests as part of code development.
- Before you start to write code, think How am I
going to prove that this code works? - If you are doing unit testing correctly
11When should I do Unit Testing?
- Think of tests as part of code development.
- Before you start to write code, think How am I
going to prove that this code works? - If you are doing unit testing correctly
- YOU ARE WRITING MORE TEST CODE THAN UNIT CODE!
- (up to 3 times as much! )
12When should I do Unit Testing?
- As part of design.
- In major programming projects it is not uncommon
to have the manager of the test team as part of
the design effort. - Their job there is to ask the question How can
we test this? - Just asking this question can have a major impact
on the design.
13When should I do Unit Testing?
- As part of development.
- As you add functionality you should be adding
tests. - Testing should be part of your daily development
process. - Start with a test application or test framework.
Get the new code working and tested there. Only
when the new code passes unit tests should it be
added to the main application.
14When should I do Unit Testing?
- As part of the build process.
- Most of the automated testing frameworks include
a console mode as well as a GUI mode. In your
build script you can add some unit testing that
will check to see if the build fails the tests.
15When should I do Unit Testing?
- As part of testing.
- This may seem redundant, but frequently
developers keep their tests to themselves and do
not pass them on to the testers. - The testing department should have access to the
unit tests as these can help them track down the
source of a problem that occurs their testing.
16When should I do Unit Testing?
- As part of deployment process.
- When an application is deployed in more than one
piece (Database, Server, Client), then unit tests
can be done to check to see if the parts fit
together as part of the deployment. (Does the
database schema match the schema used by the
server? Does the client communicate to the server
correctly?)
17When should I do Unit Testing?
- As part of install.
- You can add unit tests to the install process to
check basic functionality. Test can include - Communication with database.
- Communication with server.
- File and network rights.
- Operating system, memory, processor, etc.
18When should I do Unit Testing?
- As part of a support call.
- You can add basic unit tests into the application
under the help menu (or as a hidden keystroke). - This allows support personal to get the user to
run specific tests to locate the point of failure.
19Where should I do Unit Testing?
- On Development systems.
- On Non-Development systems.
- On systems not connected to the network.
- On User systems.
- Anywhere else.
20Who should do unit testing?
- Developers.
- Testers.
- Domain experts.
- Users.
21When should I not Unit Test.
- Unit testing can give the impression of slowing
development. - In some organizations there is a lot of pressure
to show progress, even buggy progress. Time spent
writing tests can often be perceived as wasted
effort it your code passes all the tests. - Of course, finding bugs during development saves
up to 10 times the effort finding bugs after the
product has shipped. However, sometimes it is
necessary just to get something out the door.
22When should I not Unit Test.
- There are two sayings to remember.
23When should I not Unit Test.
- There are two sayings to remember
- Anything worth doing is worth doing well.
24When should I not Unit Test.
- There are two sayings to remember
- Anything worth doing is worth doing well.
- BUT
- Anything that needs doing, needs doing badly.
25How should I do Unit testing?
- Test applications.
- The easiest way to test code is to write a
separate applications that allows you to enter
the inputs to the unit your testing and see the
outputs right away. This is ideal in situations
where you want someone else to do the testing
(someone who has particular knowledge of the
required behaviour).
26How should I do Unit testing?
- Test output.
- In some cases there can be a large number of
possible inputs and outputs that must be tested.
You can use an myBase xml file to store a
database of values to be tested and read the file
into a client dataset, you can then output to a
xml file or other text file and use a file
compare utility to test for changes in the
output. This is very handy for refactoring as you
can easily compare before and after outputs.
27How should I do Unit testing?
- Automated testing.
- There are a number of automated testing frame
works available. The most popular for Delphi is
dUnit.
28Automated testing.
- A collection of tests (Test Suites).
- Based on a Boolean test.
- Separate application or part of application.
- At least 3 frameworks for Delphi. (Dunit, Qtest,
Bubelen) - Other frame works for Java, Small talk, C etc.
29Dunit What is it?
- Automated unit testing frame work.
- SourceForge project.
- Public domain.
- Full Source available.
- Runs in GUI and Console mode.
- Wide range of tests.
- Test extensions.
30QTest
- Alternate framework.
- From BigAtticHouse (http//www.bigattichouse.com/
qtest.php)
31Bubelen
- From the Indy project
- (http//www.projectindy.org/bubelen/)