Title: Best Practices, Introduction to Testing, Junit Framework
1Best Practices, Introduction to Testing, J-unit
Framework
2Agenda
- Lab 5 Help after class
- Lab 6-9 Teams to me today
- Exam 2 July 8
- Lecture
- Best Practices
- Test Intro
- JUnit
3Miniature Milestones
- Problem Im 90 done.
- Technique
- Developers create their own estimate.
- Keep mini (no more than 1-2 days (hours))
- Milestones are 0/1
- Cover all tasks
- Use to cover short-term
- Assess and re-estimate frequently.
- Phase Project Management
-
4Change Board
- Problem Uncontrolled changes, lack of
prioritization on bug fixes, Code/Fix cycle - Technique
- Create a board of representatives
- Board has authority to accept/reject changes
- Changes are considered before they are made
- Side Effects are considered
- Phase Configuration Management
5Daily Smoke and Build Test
- Problem Unsuccessful Integration, low quality,
poor progress visibility - Technique
- All code modules turned in frequently.
- Developers keep code in buildable form.
- All interfaces are stubbed out.
- Smoke tests run automatically.
- Dummy code used where necessary.
- Breaking the build usually earns a prize.
- Phase Implementation, Code Integration
6Incremental Integration
- Problem Code integration fails. Big-bang
approach frequently used. Excessive schedule
spent in integration phase. - Technique
- Use proven integration technique
- Top-down
- Bottom-up
- Hybrid
- Phase Integration
7Software Quality Assurance
- Process (Analysis, Design, Code, Test)
- Reviews/Inspections
- Multi-tiered Testing Strategy
- Configuration Control (Code/Docs)
- Standards Compliance
- Measurement/Reporting
8Software Quality Factors
Portability Reusability Interoperabilty
Maintainability Flexibility Testability
Correctness, Reliablity, Efficiency,
Integrity Usability
9Two Key Concepts
- Validation Are we building the right thing?
Conformance to customer requirements and quality
attributes. - Verification Are we building the thing right?
Process conformance, quality activities.
10Where does testing fit in?
PHASE O Testing Debugging
PHASE 1 Testing shows the software works
PHASE 2 Testing shows the software doesnt work
PHASE 3 Testing doesnt prove anything, it
reduces risk of unacceptable
software delivery.
PHASE 4 Testing is not an act, a mental
discipline of quality.
11The Testing Quote
Testing cannot show the absence of defects, it
can only show that software defects are present.
We cannot test quality into a product, we have to
design it in.
12Test Objectives
- Tests intended to find errors
- Good test cases have high p for finding a yet
undiscovered error - Successful tests cause program failure, i.e. find
an undiscovered error. - Minimal set of test cases needs to be developed
because exhaustive testing not possible
13What we have here
- Developers do everything they can to make the
software work. - Testers do everything they can to make the
software fail.
14Testing Paradox
Every method you use to prevent or find bugs
leaves a residue of subtler bugs against which
those methods are ineffective.
Cost
Defects Found
Time
15Testing Phases
- Unit
- Integration
- Component
- System
- Usability
- Regression
- Validation
- Alpha/Beta (FUT/OT)
16Vocabulary
- Test Case a set of data/events provided for a
specific test. - Test Suite a set of test cases.
- Test Driver a program written to test a unit
module - Test Stub a module written to test a higher
level component - Test Harness a test environment to run the stubs
and drivers and check the results.
17Types of testing
- Structural (Whitebox)
- Functional (Blackbox)
- Statistical (Random)
- Mutation
- Object Oriented (State-based)
- Insert latest PhD thesis topic here
18Return of the Vocabulary
- Coverage a measure of the amount of testing to
be achieved. Normally spoken of in standard
criteria based upon test technique for a subset
of test cases. - Adequacy a measure of the overall efficiency and
effectiveness of the test suite.
19Writing a test plan
- Introduction
- Purpose
- Program Description
- Test Environment
- Test Case Descriptions
- Coverage Criteria
- Details
4. Summary
20Stubbing Functions
int main (int argc, char argv) if (argclt4)
usage() double x f(argv1,argv2)
void usage() return double f(char
arg1, char arg2) return 3.0
21Writing Drivers
int main( int argc, char argv) int i
for (i0 ilt10i) printf(SQRT of i is
i, i, sqrt(i))
22Why does testing go bad?
- Schedule compression/ Waterfall
- Writing harnesses, suites,stubs and drivers
doesnt relate directly to LOC. - Different philosophys
- Overconfidence in silver bullets
23What is xUnit?
- An automated unit test framework
- Provides the Driver for unit(s)
- Provides automatic test runs
- Provides automatic result checks
- Available for multiple languages
- cppUnit
- sUnit
- Junit
-
24Junit Terms
- Failure Expected
- Error Unexpected
- TestCase Collection of method tests
- Test Fixture Object Reuse
- TestSuite Collection of Test Cases
- TestRunner Interface
- awt, swing,text
25Using Junit (Create Fixture)
- public class ComplexTest extends TestCase
- Complex c1
- Complex c2
- protected void setUp()
- c1 new Complex(7,3)
- c2 new Complex(12,6)
-
- protected void tearDown()
-
26Using Junit (Add Test Cases)
- public void testAdd()
- Complex result c1.Add(new Complex(5,3))
- assertEquals(result.get_r(),c2.get_r())
- assertEquals(result.get_i(),c2.get_i())
-
- public void testEqual()
- assertTrue(!c2.Equal(c1))
- assertTrue(c1.Equal(new Complex(7,3)))
assertNull, assertNotNull, assertSame
27Using Junit (Make Suite)
- public static Test suite()
- TestSuite suite new TestSuite()
- suite.addTest(new ComplexTest(testAdd))
- suite.addTest(new ComplexTest(testEqual))
- return suite
28Using Junit (Invoke)
- public static void main(String args)
- junit.textui.TestRunner.run(suite())
-
- public ComplexTest(String s)
- super(s)
29The Graphical UI
30UI on Failure
31What Junit does not do
- Figure out your tests for you
- Calculate any coverage criteria
- Test GUIs
- Except extensions
- JFCUnit
- Jemmy
- Pounder
- Abbot
32Administrative
- Download latest version (3.7) from
- www.junit.org
- Setup classpath to junit.jar
- Include appropriate ui in main
- Import junit.framework.
33Next Time