Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.

Similar presentations


Presentation on theme: "CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com."— Presentation transcript:

1 CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com

2 CS-2852 Data Structures, Andrew J. Wozniewicz Agenda Introduction to Testing Automated Testing – JUnit Debugging

3 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

4 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”.

5 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”

6 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

7 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)

8 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.

9 CS-2852 Data Structures, Andrew J. Wozniewicz JUnit Demo

10 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 { }

11 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: @Test public void testEmptyCollection() { Collection collection = new ArrayList(); assertTrue(collection.isEmpty()); }

12 CS-2852 Data Structures, Andrew J. Wozniewicz Writing a Simple JUnit Test Step 3: Run the test from within : Run Run As... JUnit Test

13 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)

14 CS-2852 Data Structures, Andrew J. Wozniewicz JUnit Test Methods fail(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

15 CS-2852 Data Structures, Andrew J. Wozniewicz Summary Introduction to Testing Automated Testing – JUnit Debugging

16 Questions? Image copyright © 2010 andyjphoto.com


Download ppt "CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com."

Similar presentations


Ads by Google