CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
-
Upload
anis-hodges -
Category
Documents
-
view
216 -
download
0
description
Transcript of CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
CS-2852Data StructuresLECTURE 7B
Andrew J. Wozniewicz
Image copyright © 2010 andyjphoto.com
CS-2852 Data Structures, Andrew J. Wozniewicz
Agenda• Introduction to Testing• Automated Testing– JUnit
• Debugging
CS-2852 Data Structures, Andrew J. Wozniewicz
What is Testing?
The purpose of testing is to find bugs.No amount of testing “proves”
correctness – impossible to test all scenarios.
Process of exercising a program (or its part) under controlled conditions and verifying
that the results are as expected.
DEFINITION
CS-2852 Data Structures, Andrew J. Wozniewicz
Classification of Testing I• Unit testing– Test a single method or class.
• Integration testing– Test a cluster of related classes, subsystems,
etc.• System testing– Test the whole program, as it will be used.
• Acceptance testing– System testing for the benefit of the
“customer”.
CS-2852 Data Structures, Andrew J. Wozniewicz
Classification of Testing II• Black-Box Testing– Based on public interfaces and external
specs– “Functional testing”
• White-Box Testing– Based on the intimate knowledge of the
implementation.– Exercise all/as many as possible paths of
execution– “Coverage testing”
CS-2852 Data Structures, Andrew J. Wozniewicz
Testing Ideas• Boundary Conditions– Special cases that might cause the
program to fail.• Test Scaffolding– Stubs, Mockups• Skeleton with minimal implementation.
– Pre- and Postconditions– Driver Programs
CS-2852 Data Structures, Andrew J. Wozniewicz
Unit Testing• Unit Test – Code written by a developer that tests a
specific functionality.– Used as part of specifying out the system
(pre-code)– Used for regression testing (post-code)
CS-2852 Data Structures, Andrew J. Wozniewicz
JUnit Unit Testing Framework
• By Kent Beck and Erich Gamma• JUnit is a simple, open-source
framework to write repeatable tests.• Home Page: www.junit.org• Automatic: JUnit tests do not require
human judgment to interpret.• Easy to set up a multitude of tests and
always run them together.
CS-2852 Data Structures, Andrew J. Wozniewicz
JUnit Demo
CS-2852 Data Structures, Andrew J. Wozniewicz
Writing a Simple JUnit Test• Step 1: Create a test class
import org.junit.*; import static org.junit.Assert.*; import java.util.*;
public class SimpleTest {
}
CS-2852 Data Structures, Andrew J. Wozniewicz
Writing a Simple JUnit Test• Step 2: Write a test method (annotated
with @Test) that asserts expected results on the object under test:
@Testpublic void testEmptyCollection() { Collection collection = new ArrayList(); assertTrue(collection.isEmpty());}
CS-2852 Data Structures, Andrew J. Wozniewicz
Writing a Simple JUnit Test• Step 3: Run the test from within :
RunRun As...JUnit Test
CS-2852 Data Structures, Andrew J. Wozniewicz
JUnit Annotations@Test public void method()@Before public void method()@After public void method()@BeforeClass public void method()@AfterClass public void method()@Ignore@Test(expected=IllegalArgumentException.class)@Test(timeout=100)
CS-2852 Data Structures, Andrew J. Wozniewicz
JUnit Test Methodsfail(String) assertTrue(true); assertsEquals([String message], expected, actual) assertsEquals([String message], expected, actual, tolerance) assertNull([message], object) assertNotNull([message], object) assertSame([String], expected, actual) assertNotSame([String], expected, actual) assertTrue([message], boolean condition)
Equals: Values, Same: References
CS-2852 Data Structures, Andrew J. Wozniewicz
Summary• Introduction to Testing• Automated Testing– JUnit
• Debugging
Questions?
Image copyright © 2010 andyjphoto.com