Testing Stragegies. Black Box Testing. Test case

Similar documents
Testing. CMSC 433 Programming Language Technologies and Paradigms Spring A Real Testing Example. Example (Black Box)?

Approach for Unit testing with the help of JUnit...

White box testing. White-box testing. Types of WBT 24/03/15. Advanced Programming

Test-Driven Development JUnit

xtreme Programming (summary of Kent Beck s XP book) Stefan Resmerita, WS2015

Introduction to JUnit. Data Structures and Algorithms for Language Processing

Tools for Unit Test - JUnit

CHAPTER 1INTRODUCTION... 3 CHAPTER 2INSTALLING ECLIPSE...

Tools for Unit Test JUnit

Test-Driven Development JUnit

Practical Objects: Test Driven Software Development using JUnit

Test-Driven Development (a.k.a. Design to Test) CSE260, Computer Science B: Honors Stony Brook University

EECS 4313 Software Engineering Testing

Automated Acceptance Testing

Test automation / JUnit. Building automatically repeatable test suites

Test automation Test automation / JUnit

Testing & Debugging TB-1

Chapter 3. Unit Testing with JUnit and Debugging. Testing with JUnit getting started. Note

Agile Software Development. Lecture 7: Software Testing

Object Oriented Software Design - I

JUnit on Eclipse. Chien-Tsun Chen Sep. 23, 2003

Chapter 14 Software Testing Techniques

INTRODUCTION TO JAVA PROGRAMMING JAVA FUNDAMENTALS PART 2

Problem other classes messing with my stuff!

print statements, debugger expressions, test scripts. Writing expressions in a debugger only that t a program works now. An application typically

Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

CMSC 132: OBJECT-ORIENTED PROGRAMMING II

No!! 1B1b. Testing. Testing. Perfection. Perfection, or Lack of It. Two V s. Errors. 1B11 Lecture Slides. Copyright 2004, Graham Roberts 1

JUnit Test Patterns in Rational XDE

Automated GUI testing. How to test an interactive application automatically?

Testing. Topics. Types of Testing. Types of Testing

Basic Keywords Practice Session

Lecture 15 Software Testing

Introduction to Programming Using Java (98-388)

South Africa

Unit Testing with JUnit and CppUnit

Program Correctness and Efficiency. Chapter 2

Annotations in Java (JUnit)

JUnit Testing Framework Architecture

Tuesday, November 15. Testing

Fundamentals of Object Oriented Programming

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Overview. State-of-the-Art. Relative cost of error correction. CS 619 Introduction to OO Design and Development. Testing.

COMP 354 TDD and Refactoring

JUNIT - API. The most important package in JUnit is junit.framework which contain all the core classes. Some of the important class are

Software Engineering I (02161)

Efficient Regression Test Model for Object Oriented Software

Practical Unit Testing junit. Atul Prakash

Tutorials for Struts, EJB, xdoclet and eclipse.

What is Testing? Table of Contents

Announcements. Lab tomorrow. Quiz Thursday P3 due Friday. Exceptions and unit testing

6.005 Elements of Software Construction Fall 2008

VIRTUAL FUNCTIONS Chapter 10

Chapter 15. Software Testing The assert Statement

Advanced Software Engineering

CSE 326: Data Structures. Section notes, 4/9/2009

Test automation / JUnit. Building automatically repeatable test suites

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

ASSIGNMENT 5 Objects, Files, and More Garage Management

Chapter 9. Exception Handling. Copyright 2016 Pearson Inc. All rights reserved.

A Web-based Testing Tool

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

Lecture 05: Methods. AITI Nigeria Summer 2012 University of Lagos.

Java Programming Training for Experienced Programmers (5 Days)

Controls Structure for Repetition

CSE 8B Intro to CS: Java

Stephen Edwards. What is unit testing? Manuel Pérez- Quiñones. Virginia Tech. You betcha! For you: Repeatedly check behaviors of many student programs

Lecture 3. Black- box Tes3ng

Jtest Tutorial. Tutorial

Testing Exceptions with Enforcer

CS159. Nathan Sprague. September 30, 2015

ASSIGNMENT 5 Objects, Files, and a Music Player

Computer Components. Software{ User Programs. Operating System. Hardware

F. Tip and M. Weintraub FUNCTIONAL TESTING

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Why Design by Contract! CS 619 Introduction to OO Design and Development. Design by Contract. Fall 2012

Object Oriented Programming. Week 1 Part 3 Writing Java with Eclipse and JUnit

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Software Test. Levels of test. Types of test. Regression test The JUnit tool for unit testing Java programs. System test Integration test Unit test

16.410: Jump Starting With Java

RUNNING AND CREATING JUNIT TESTS WITH FUEGO FUEGO V5. Pablo Victory

Outline HW2. Feedback. CS1007: Object Oriented Design and Programming in Java

Thinking Functionally

CSE 331 Final Exam 3/16/15 Sample Solution

mvn package -Dmaven.test.skip=false //builds DSpace and runs tests

EINDHOVEN UNIVERSITY OF TECHNOLOGY

Learning outcomes. Systems Engineering. Debugging Process. Debugging Process. Review

SWE 434 Software Testing and Validation

TEST DRIVEN DEVELOPMENT

ULC Test Framework Guide. Canoo RIA-Suite 2014 Update 4

Assignment: TwoMethods Submitted to WebCat

1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 4, 2005

WA1278 Introduction to Java Using Eclipse

Introduction to Automated Unit Testing (xunit) Brian Nielsen Arne Skou

linaye/gl.html

Checking Current Code Coverage

Manuel Oriol, CHCRC-C, Software Testing ABB

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Verification and Validation. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 22 Slide 1

Transcription:

References: Teach Yourself Object-Oriented Programming in 21 Days by A.Sintes, 1 Testing Stragegies Test case a set of inputs and expected outputs looks at specific piece of functionality to determine if system behaves as expected failed test = system bug every test case must pass before continuing use black box and white box testing 2 Black Box Testing Tests that system functions as expected When testing individual classes, b.b. testing is based on functional requirements of the class When testing whole system, b.b. testing is based on use cases e.g. if a method adds two numbers, test verifies if output is/is not the correct sum 3 1

White Box Testing Tests are based on the method s implementation 100% code coverage is aimed for Tests every branch of the code e.g. if method divides two numbers, with an error branch for divide by 0, a test case must be devised that executes the error condition. 4 5 Unit Testing examines only one feature at a time examines a single class in isolation sends a message to an object and verifies that the expected result is returned each class should have a corresponding unit test should be done throughout development can be white box and black box 6 2

Integration Testing tests that objects interact properly can be based on white box and black box testing needed for each important interaction in the system 7 System Testing verifies the whole system performs as described by use cases should also test things that are not described by use cases to verify that unexpected conditions are handled gracefully includes stress and performance tests -- done in environment that matches production environment 8 System Testing Related to acceptance testing (tests run by the customer on the delivered software) One test can touch many different objects and subsystems All tests must pass before leaving an iteration 9 3

Regression Testing Examines changes to the system that have already been tested and validated If a change is made, the code and any code that was dependent on it is retested Reruns the unit, integration and system tests 10 11 Unit Testing Testing should be done continuously during development Should write a unit test for each class Unit test examines the lowest-level building block of an OO program: an object Can have any number of test cases Each test case checks one feature of the object 12 4

Example Unit Test Public class SavingsAccountTest { public static void main ( String[] args ) { SavingsAccountTest sat = new SavingsAccountTest(); sat.test_applyinginterest(); One test case public void test_applyinginterest() { SavingsAccount acct = new SavingsAccount( 10000.00,.05 ); acct.addinterest(); print_getbalanceresult( acct.getbalance(), 10500.00, 1 ); private void print_getbalanceresult ( double actual, double expected, int test ) { if (actual == expected ) { //passed System.out.println( PASS: test# +test+ interest applied ok ); else { //failed System.out.println( FAIL: test# +test+ interest applied wrong ); System.out.println( value returned: + actual ); System.out.println( expected value: + expected ); 13 Why Do Unit Testing? Unit tests avoid manual validations that are usually error prone and always time consuming help detect errors at lowest level of development help you know when you are done writing a class -- i.e., when all unit tests pass help you design classes when you write the test case before you write the class help you to refactor code (instant feedback on changes 14 Frameworks Framework: a reusable domain model contains all classes common to a domain of problems and serves as basis for a specific application in the domain you extend the classes in the framework and provide your own problem-specific classes to create an application Easier to use a testing framework 15 5

Testing Framework Provides a skeleton you can reuse for writing and executing unit tests Contains base classes for writing unit tests, built-in support for test automation and utilities for interpreting and reporting output Junit is a well-known testing framework for testing Java classes 16 References: Teach Yourself Object-Oriented Programming in 21 Days by A.Sintes, Junit.org Some slides by Quddus Chong 17 Testing with JUnit The JUnit tool is available from www.junit.org The XP programming philosophy is: program incrementally, test-first, and integrate continuously. Tests are generally written method-bymethod. A test should be created whenever the programmer perceives a risk in the code. 18 6

Testing with JUnit Key benefits of automated testing: You can run the tests over and over again Have a framework that facilitates testing Better confidence in quality of code By testing first, the design becomes more focused on implementing behavior (less wasteful code) 19 How to do it (The Test/Code cycle) Write one test Compile the test it should fail to compile, because you haven t implemented the code that the test calls. Implement just enough to compile. Run the test and see it fail. Implement just enough to make the test pass. Run the test and see it pass. Refactor for clarity and remove duplication. Repeat from top. 20 JUnit Has classes for writing unit tests, for validating output and for running test cases in a GUI or command-line environment junit.framework.testcase is base class for defining unit tests To write unit tests, write a class that inherits from TestCase, overrides some methods, and provides its own test case methods 21 7

What s inside a TestCase? TestCase TestCase constructor() IndividualTest() IndividualTest() IndividualTest() TestSuite import static org.junit.assert.*; import org.junit.before; import org.junit.test; public class TutorialTest { @Before protected void setup() throws Exception { super.setup(); @Test public void testsayhello() { HelloWorld world = new HelloWorld(); asserttrue("world is created", world!=null ); assertequals("hello World", world.sayhello() ); 22 JUnit Testing Unit test = test of a single class Design test cases during implementation Run tests after every implementation change When you find a bug, add a test case that catches it 23 JUnit 4.0 Test class name = tested class name + Test Test methods start with test import junit.framework.*; @Test public class DayTest extends TestCase { public void testadd() {... public void testdaysbetween() {...... 24 8

JUnit 4.0 Each test case ends with assertion Test framework catches assertion failures @Test public void testadd() { Day d1 = new Day(1970, 1, 1); int n = 1000; Day d2 = d1.adddays(n); assert d2.daysfrom(d1) == n; 25 JUnit The name of any test case method must begin with test The method must be preceded by @Test A test suite is a mechanism for running multiple test cases 26 Installing/Using JUnit Download.zip file (latest version is 3.7) and unzip. Make sure that junit.jar is on your classpath. JUnit is built in to Eclipse To run JUnit from Eclipse: Right click on source file Choose New JUnit Test Case If junit.jar is not on build path, add it If you choose setup, then you can declare objects once; otherwise, you must declare an object locally to test 27 9

Test Suite @Test public static Test suite () { TestSuite suite= new TestSuite(); suite.addtest(new TutorialTest ("testsayhello")); return suite; 28 10