1 / 16

EMOOSE 2001-2002 Object-Oriented Software E volution

EMOOSE 2001-2002 Object-Oriented Software E volution. Extreme Programming. Dr. Tom Mens tom.mens@vub.ac.be Programming Technology Lab http://prog.vub.ac.be Vrije Universiteit Brussel Pleinlaan 2 - 1050 Brussel Belgium. Characteristics of XP. Pair Programming Unit Testing Refactoring

Télécharger la présentation

EMOOSE 2001-2002 Object-Oriented Software E volution

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. EMOOSE 2001-2002Object-Oriented Software Evolution Extreme Programming Dr. Tom Mens tom.mens@vub.ac.be Programming Technology Lab http://prog.vub.ac.be Vrije Universiteit Brussel Pleinlaan 2 - 1050 Brussel Belgium

  2. Characteristics of XP • Pair Programming • Unit Testing • Refactoring • Write tests before you implement new functionality or refactor the code • Run tests after the change to check correctness

  3. Testing: Definitions • Regression testing • selective retesting of a system or component to verify that modifications have not caused unintended effects and that the system or component still complies with its specified requirements • Unit testing • Tests are associated to individual hardware or software units or groups of related units • the tests identify clearly which part of the system they thest • E.g., a particular class, method or package • IEEE Standard 1990 • Institute of Electrical and Electronics Engineers, Standard Computer Dictionary: A Compilation of IEEE Standard Computer Glossaries. NewYork, NY: 1990

  4. Unit Testing • TestCase • A collection of tests for a given unit (e.g., a class) • Each test is implemented as an ordinary Java method without parameter and return type • TestSuite • A collection of test cases, one for every relevant unit • Testing frameworks available for all main OO languages • Java: JUnit (www.JUnit.org) • Smalltalk: SUnit • C++ • Perl

  5. JUnit Class Hierarchy Object TestSuite Assert addTest addTestSuite run assertEquals assertNotNull assertNull assertSame assertTrue run Composite design pattern:TestSuite bundles a set of TestCases and TestSuites <<interface>> Test TestCase All errors and failures are collected in a TestResult TestResult setUp tearDown run runTest run countTestCases addError addFailure run

  6. JUnit sequence diagram :TestRunner :TestSuite tc:TestCase tr:TestResult run(tr) run(tr) run(tc) runBare() setUp() runTest() tearDown() addFailure()

  7. Unit Testing in Java:TestCase Example import junit.framework.TestCase; public class PacketTest extends TestCase { private Packet p1, p2; private Node n; public PacketTest(String arg0) { super(arg0); } //constructor protected void setUp() throws Exception { super.setUp(); n = new Node("Node 1"); p1 = new Packet(”contents 1", n); p2 = new Packet(”contents 2", n); // same addressee as p1 } public void testPacketContents() { assertNotSame(p1,p2); } protected void tearDown() throws Exception { super.tearDown(); } public static void main(String args[]) { junit.swingui.TestRunner.run(PacketTest.class); } }

  8. Unit Testing in Java:TestSuite Example import junit.framework.Test; import junit.framework.TestSuite; public class LANTests { public static void main(String[] args) { junit.swingui.TestRunner.run(LANTests.class); } public static Test suite() { TestSuite suite = new TestSuite("Test for LAN"); suite.addTest(new TestSuite(NodeTest.class)); suite.addTest(new TestSuite(PacketTest.class)); suite.addTest(new TestSuite(PrintserverTest.class)); suite.addTest(new TestSuite(WorkstationTest.class)); return suite; } }

  9. Unit Testing in Java:Junit Screenshot

  10. Unit Testing in JavaJUnit • JUnit (3.8.1) • Different user interfaces available • Swing, AWT, text • Hierarchical view on the test suites • Plug-in for Eclipse • Transparently integrated into the Eclipse IDE • Support for tracing of test failures

  11. Unit Testing in Eclipse IDE:Screenshot

  12. Unit Testing in Java:Dealing with Exceptions TestCase setUp tearDown run runTest Exception ExceptionTestCase In junit.extensions addTest addTestSuite run runTest Application-specific code MyException MyExceptionTest

  13. Unit Testing in Java:ExceptionTestCase Example import junit.extensions.ExceptionTestCase; public class CyclingTest extends ExceptionTestCase { private Packet p; private Workstation w; private Printserver s; public CyclingTest(String a0, Class a1) { super(a0,a1); } //constructor protected void setUp() throws Exception { // create 2-node network with unknown-destination packet super.setUp(); w = new Workstation("Workstation"); s = new Printserver(”Printserver", w); w.setNextNode(s); p = new Packet(”blabla", new Node("Node"); } public void testCycling() throws UnknownDestination { p.originator = w; w.send(p); // this throws an UnknownDestination } }

  14. Unit Testing in Java:ExceptionTestCase Example import junit.framework.Test; import junit.framework.TestSuite; public class LANTests { public static void main(String[] args) { junit.swingui.TestRunner.run(LANTests.class); } public static Test suite() { TestSuite suite = new TestSuite("Test for LAN"); suite.addTest(new TestSuite(NodeTest.class)); … suite.addTest(new CyclingTest( "testCycling", UnknownDestination.class)); return suite; } }

  15. Unit Testing in JavaExceptions alternative solution import junit.framework.TestCase; public class WorkstationTest extends TestCase { private Workstation w; private Printserver s; private Packet p; public WorkstationTest(String arg0) { super(arg0); } //constructor protected void setUp() throws Exception { super.setUp(); w = new Workstation("Workstation"); s = new Printserver(”Printserver", w); w.setNextNode(s); p = new Packet(”contents", new Node("Node"); } public void testOriginator() {…} public void testCycling() { try { p.originator = w; w.send(p); } catch (UnknownDestination e) {return;} fail("I expected an UnknownDestination here…"); } public static void main(String args[]) { junit.swingui.TestRunner.run(PacketTest.class); } }

  16. References • K. Beck, E. Gamma. Test Infected: Programmers Love Writing Tests. JUnit Documentation, 1998 • K. Beck. Extreme Programming Explained: Embrace Change. Addison Wesley, 2000

More Related