1 CS115 Class 15: Testing Due today –User Manual –Software Inspections –Review: Testing Next time –Review No Silver Bullet.

Slides:



Advertisements
Similar presentations
Unit Testing Australian Development Centre Brisbane, Australia.
Advertisements

xUnit Test Patterns (Some) xUnit Test Patterns (in practice) by Adam Czepil.
Computer Science 209 Testing With JUnit. Why Test? I don ’ t have time, I ’ ve got a deadline to meet The more pressure I feel, the fewer tests I will.
J-Unit Framework.
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Approach of Unit testing with the help of JUnit Satish Mishra
Testing and Debugging CS221 – 2/13/09. Airline Program.
1 CS115 Class 16: Testing (continued) Due today –Review: No Silver Bullet For next time –Deliverable: Unit Tests – one per group member –Review: The New.
Well-behaved objects 4.0 Testing. 2 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling Main concepts to.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
JUnit, Revisited 17-Apr-17.
Adapted from Prof. Necula, CS 169, Berkeley1 Testing V Software Engineering Lecture 7, Spring 2008 Clark Barrett, New York University (with.
7. Goals of Software Design Design faces many challenges to produce a good product, e.g. shifting requirements. But what do we mean by good ? We need some.
Writing a Unit test Using JUnit At the top of the file include: import junit.framework.TestCase; The main class of the file must be: public Must extend.
JUnit Tutorial. Automating Testing Process Testing is boring and time-consuming, it is not a job for “human” Why not automating the testing process? Test.
Software Testing. “Software and Cathedrals are much the same: First we build them, then we pray!!!” -Sam Redwine, Jr.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
Unit Testing Discussion C. Unit Test ● public Method is smallest unit of code ● Input/output transformation ● Test if the method does what it claims ●
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
Programmer Testing Testing all things Java using JUnit and extensions.
Terms: Test (Case) vs. Test Suite
Lesson 7 Unit Testing /JUnit/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Lecture 6 Software Testing and jUnit CS140 Dick Steflik.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
TESTING.
Testing in Extreme Programming
Testing Basics of Testing Presented by: Vijay.C.G – Glister Tech.
Unit testing Unit testing TDD with JUnit. Unit Testing Unit testing with JUnit 2 Testing concepts Unit testing Testing tools JUnit Practical use of tools.
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
16 October Reminder Types of Testing: Purpose  Functional testing  Usability testing  Conformance testing  Performance testing  Acceptance.
CSC 395 – Software Engineering Lecture 10: Execution-based Testing –or– We can make it better than it was. Better...faster...agiler.
Software Construction Lecture 18 Software Testing.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
JUnit Dwight Deugo Nesa Matic
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
JUnit Dwight Deugo Nesa Matic
EMBEDDED REAL-TIME, INC. December 8, 2015 Java Unit Mark Mosher Rochester Java Users Group.
Software Engineering 2004 Jyrki Nummenmaa 1 BACKGROUND There is no way to generally test programs exhaustively (that is, going through all execution.
Testing. Today’s Topics Why Testing? Basic Definitions Kinds of Testing Test-driven Development Code Reviews (not testing) 1.
JUnit A framework which provides hooks for easy testing of your Java code, as it's built Note: The examples from these slides can be found in ~kschmidt/public_html/CS265/Labs/Java/Junit.
Using UML, Patterns, and Java Object-Oriented Software Engineering Chapter 11, Testing.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
Unit Testing CSSE 514 Programming Methods 4/19/01.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
Test a Little, Code a Little Colin Sharples IBM Global Services New Zealand Colin Sharples IBM Global Services New Zealand.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Unit Testing with FlexUnit
Test Plans Test Driven Development – Unit test plan first Code coverage Automated Regression built as you go Debug is easier Serves as system doc – Still.
Automated Testing with PHPUnit. How do you know your code works?
Software Engineering Lecture 11 Software Testing Presenter: Josef Hallberg 1.
1 March 12, Testing William Cohen NCSU CSC 591W March 12, 2008.
Getting Started with JUnit Getting Started with JUnit The benefits and ease of writing and running JUnit test cases and test suites. The benefits and ease.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Software Construction Lab 10 Unit Testing with JUnit
Testing Tutorial 7.
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
Computer Science 209 Testing With JUnit.
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
ECOM 6330 Java Parallel and Distributed computing
Joel Adams and Jeremy Frens Calvin College
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
Testing Slides adopted from John Jannotti, Brown University
Presentation transcript:

1 CS115 Class 15: Testing Due today –User Manual –Software Inspections –Review: Testing Next time –Review No Silver Bullet

2 French Guyana, June 4, 1996 $800 million software failure

3 Mars Climate Orbiter –The 125 million dollar Mars Climate Orbiter is assumed lost by officials at NASA. The failure responsible for loss of the orbiter is attributed to a failure of NASA’s system engineer process. The process did not specify the system of measurement to be used on the project. As a result, one of the development teams used Imperial measurement while the other used the metric system of measurement. When parameters from one module were passed to another during orbit navigation correct, no conversion was performed, resulting in the loss of the craft.

4

5 More BSOD Embarrassments

6

7 Economic Impact NIST study –On CNN.com - April 27,

8 Basic Definitions Error-mistake or deviation from correct value Failure-unacceptable system behavior Defect/fault-flaw in any part of system that may cause a failure

9 Testing Objective Find defects/faults –Find them effectively as many as possible –Find them efficiently as many as possible given testing time

10 Testing scope Unit Integration System Acceptance Alpha/Beta

11 Test approach White box Black box

12 Software Development Today ProgrammerTester Decision Maker Why do we have this structure?

13 Typical Scenario (1) ProgrammerTester Decision Maker “I’m done.” “It doesn’t #$%& compile!” “OK, calm down. We’ll slip the schedule. Try again.”

14 Typical Scenario (2) ProgrammerTester Decision Maker “I’m done.” “It doesn’t install!” “Now remember, we’re all in this together. Try again.”

15 Typical Scenario (3) ProgrammerTester Decision Maker “I’m done.” “It does the wrong thing in half the tests.” “Let’s have a meeting to straighten out the spec.” “No, half of your tests are wrong!”

16 Typical Scenario (4) ProgrammerTester Decision Maker “I’m done.” “It still fails some tests we agreed on.” “Try again, but please hurry up!”

17 Typical Scenario (5) ProgrammerTester Decision Maker “I’m done.” “Yes, it’s done!” “Oops, the world has changed. Here’s the new spec.”

18 Software Development Today ProgrammerTester Decision Maker Why do we have this structure?

19 Standard Testing Questions How shall we generate/select test cases? Did this test execution succeed or fail? How do we know when to stop testing?

20 Summary Testing is hard –If done manually, also very expensive and boring Use inspections! –Will save more time in testing and debugging A number of techniques can make testing effective –Randomized testing –Exhaustive testing on small examples –Regression testing with nightly build

21 Back to Design Testing has a profound impact on design –Because some designs are easier to test Design software so it can be tested!

22 Principles of Testability Avoid unpredictable results –No unnecessary non-deterministic behavior Design in self-checking –At appropriate places have system check its own work Asserts –May require adding some redundancy to the code Have a test interface Minimize interactions between features –Number of interactions can easily grow huge –Rich breeding ground for bugs

23 JUnit Test automation

24 Benefits of JUnit Free - Automatic check of expected vs. actual Simple to use – quick to write and run Tests are written in Java

25 Design of JUnit Built around Command pattern –each method under test is represented by a separate test method

26 JUnit Sample Unit Test write tests for all methods in a class import junit.framework.TestCase public class ShoppingCartTest extends TestCase { protected void setUp() {…} protected void tearDown() {…} public void testEmpty() {…} public void testAddItem() {…} }

27 How to create a test suite import junit.framework.TestSuite; public class EcommerceTestSuite { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(ShoppingCartTest.class); suite.addTest(CreditCardTestSuite.suite()); } /** * Runs the test suite using the textual runner. */ public static void main(String[] args) { junit.textui.TestRunner.run(suite()); }

28 A GUI for running the test suite java junit.swingui.TestRunner EcommerceTestSuite

29 Initialization called before every test case method protected void setUp() { cart = new ShoppingCart(); book1 = new Product("Pragmatic Unit Testing", 29.95); cart.addItem(book1); }

30 Clean up called after every test case method protected void tearDown() { // set to null any references to big objects

31 Tests the empty method public void testEmpty() { cart.empty(); assertEquals(0, cart.getItemCount()); }

32 Tests addItem method public void testAddItem() { Product book2 = new Product("Pragmatic Project Automation", 29.95); cart.addItem(book2); double expectedBalance = book1.getPrice() + book2.getPrice(); assertEquals(expectedBalance, cart.getBalance()); assertEquals(2, cart.getItemCount()); }

33 Output of JUnit >java junit.textui.TestRunner TestServer 1) testAddItem AssertionFailedError: expected: but was:

34 JUnit assertXXX assertEquals(x,y) //.equals, or values assertFalse(boolean expr) assertNotNull(obj ref) assertNotSame(x, y) // using == assertNull() assertSame() assertTrue() fail() public void testPassNullsToConstructor(){ try{ Server s = new Server(null, null); fail(“Expected IllegalArgumentException”); } catch (IllegalArgumentException expected){} }

35 JUnit Sequence New test case for every test method For each test method –create new object no sharing of instance variables between tests –setUp() –test –tearDown()

36 JUnit Practices One function check per test method –usually one assert per test sometimes more –failure aborts entire method Many test per TestCase Can group multiple TestCase into a TestSuite

37 JUnit Recommendations Add JUnit tests in your code –run regularly (eg before SVN commit) Benefits: –catch errors early easier to debug, easier to fix –reduce cost of integration testing –reduce risk of large, untested code base of late slips in schedule (no time to recover) increase confidence, reduce stress

38 More details... JUnit home: Tutorial Also (thanks Stan) –

39 “Best Practices” Session By now, you have now developed some expertise in your particular specialization –(tester, coder, documenter, facilitator) Group by specialization to discuss –what knowledge you’ve gained –what works, what doesn’t –tips to help other teams Short (5min) presentation using doc camera