© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.1 Unit Testing Explained How to support changes? How to support basic but synchronized documentation?

Slides:



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

Test-First Programming. The tests should drive you to write the code, the reason you write code is to get a test to succeed, and you should only write.
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.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
Smalltalk Connections 1 Test Driven Development (TDD) Presented by Victor Goldberg, Ph.D.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
Testing and Debugging CS221 – 2/13/09. Airline Program.
Testing and Debugging pt.2 Intro to Complexity CS221 – 2/18/09.
3. A Testing Framework. © O. Nierstrasz P2 — A Testing Framework 3.2 A Testing Framework Overview  What is a framework?  What is an Annotation?  JUnit.
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.
© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.1 9. Refactoring Refactoring  What is it?  Why is it necessary?  Examples  Tool support Refactoring.
JUnit. What is unit testing? A unit is the smallest testable part of an application. A unit test automatically verifies the correctness of the unit. There.
3. A Testing Framework. © O. Nierstrasz P2 — A Testing Framework 3.2 A Testing Framework Overview  What is a framework?  JUnit — a simple testing framework.
24-Jun-15 JUnit. 2 Test suites Obviously you have to test your code to get it working in the first place You can do ad hoc testing (running whatever tests.
OOP #10: Correctness Fritz Henglein. Wrap-up: Types A type is a collection of objects with common behavior (operations and properties). (Abstract) types.
© S. Demeyer, S. Ducasse, O. Nierstrasz Migration.1 5. Testing and Migration What and Why  Reengineering Life-Cycle Tests: Your Life Insurance !  Grow.
3. A Testing Framework. © O. Nierstrasz P2 — A Testing Framework 3.2 A Testing Framework Sources  JUnit 4.0 documentation (from
DEBUGGERS For CS302 Data Structures Course Slides prepared by TALHA OZ (most of the text is from
CODING Research Data Management. Research Data Management Coding When writing software or analytical code it is important that others and your future.
Unit Testing Using PyUnit Monther Suboh Yazan Hamam Saddam Al-Mahasneh Miran Ahmad
CS1101: Programming Methodology Aaron Tan.
Test-Driven Development With Visual Studio 2005 Erno de Weerd Info Support.
1 Spidering the Web in Python CSC 161: The Art of Programming Prof. Henry Kautz 11/23/2009.
Test Driven Development TDD. Testing ”Testing can never demonstrate the absence of errors in software, only their presence” Edsger W. Dijkstra (but it.
Introduction to VB.NET Tonga Institute of Higher Education.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Introduction to Unit Testing Jun-Ru Chang 2012/05/03.
Process Design (Requirements). Recall the Four Steps of Problem Solving * Orient Plan Execute Test These apply to any kind of problem, not just spreadsheet.
Testing in Extreme Programming
1 Testing With The JUnit Framwork Carl-Fredrik Sørensen, PhD Fellow
T-unit: Tcl Unit Test Package Automated Unit Test Package For Tcl Procedures Final Presentation Joseph Boyle Loyola Marymount University.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
Debugging. Compile problems Read the whole complaint! Runtime problems –Exceptions –Incorrect behavior.
Dr. Tom WayCSC Testing and Test-Driven Development CSC 4700 Software Engineering Based on Sommerville slides.
Testing and Debugging Version 1.0. All kinds of things can go wrong when you are developing a program. The compiler discovers syntax errors in your code.
Testing. 2 Overview Testing and debugging are important activities in software development. Techniques and tools are introduced. Material borrowed here.
COMP 121 Week 1: Testing and Debugging. Testing Program testing can be used to show the presence of bugs, but never to show their absence! ~ Edsger Dijkstra.
Testing and Debugging Session 9 LBSC 790 / INFM 718B Building the Human-Computer Interface.
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.
A Practical Guide To Unit Testing John E. Boal TestDrivenDeveloper.com.
(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.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Refactoring & Testability. Testing in OOP programming No life in flexible methodologies and for refactoring- infected developers without SOME kind of.
A tool for test-driven development
Week81 APCS-AB: Java Unit Testing Information today from “Unit Testing in BlueJ” October 28, 2005.
Design - programming Cmpe 450 Fall Dynamic Analysis Software quality Design carefully from the start Simple and clean Fewer errors Finding errors.
JUnit Don Braffitt Updated: 10-Jun-2011.
Henrik Bærbak Christensen1 Test Driven Development “TDD” Summary.
CPSC 871 John D. McGregor Module 8 Session 1 Testing.
1 COS 260 DAY 15 Tony Gauvin. 2 Agenda Questions? 6 th Mini quiz Today –Chapter 6 Assignment 4 posted –Due Nov 9 Capstone progress reports are due –Brief.
Refactoring1 Improving the structure of existing code.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Testing JUnit Testing. Testing Testing can mean many different things It certainly includes running a completed program with various inputs It also includes.
Topic: Junit Presenters: Govindaramanujam, Sama & Jansen, Erwin.
13-Mar-16 Scalatest. Scalatest variants Scalatest is a testing framework inspired by JUnit Scalatest comes in various styles: FunSuite, FlatSpec, FunSpec,
CPSC 372 John D. McGregor Module 8 Session 1 Testing.
Software Construction Lab 10 Unit Testing with JUnit
Smalltalk Testing - SUnit
Unit testing Java programs Using JUnit
Test Driven Development 1 November Agenda  What is TDD ?  Steps to start  Refactoring  TDD terminology  Benefits  JUnit  Mocktio  Continuous.
Computer Science 209 Testing With JUnit.
CSCE 315 – Programming Studio, Fall 2017 Tanzir Ahmed
Introduction to Testing, SUnit and Error Handling
Test-driven development (TDD)
Testing and Test-Driven Development CSC 4700 Software Engineering
Improving the structure of existing code
What is Software Testing?
Joel Adams and Jeremy Frens Calvin College
Presentation transcript:

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.1 Unit Testing Explained How to support changes? How to support basic but synchronized documentation?

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.2 Changes Changes are costly  Client checking…  Documentation Introduce bugs, hidden ripple effects System “sclerosis” Less and less axes of freedom

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.3 Unit Testing Lot of theory and practices behind tests  Black-box, whitebox, paths… Put to the light again with XP emergence How can I trust that the changes did not destroy something? What is my confidence in the system? Refactoring are ok but when I change 3 to 5, is my system still working

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.4 Tests Tests represent your trust in the system Build them incrementally  Do not need to focus on everything  When a new bug shows up, write a test Even better write them before the code  Act as your first client, better interface Active documentation always in sync

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.5 Testing Style “The style here is to write a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run.” write unit tests that thoroughly test a single class write tests as you develop (even before you implement) write tests for every new piece of functionality “Developers should spend 25-50% of their time developing tests.”

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.6 But I can’t cover everything! Sure! Nobody can but When someone discovers a defect in your code, first write a test that demonstrates the defect.  Then debug until the test succeeds. “Whenever you are tempted to type something into a print statement or a debugger expression, write it as a test instead.” Martin Fowler

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.7 Good Tests Repeatable No human intervention “self-described” Change less often than the system Tells a story

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.8 JUnit Junit (inspired by Sunit) is a simple “testing framework” that provides: classes for writing Test Cases and Test Suites methods for setting up and cleaning up test data (“fixtures”) methods for making assertions textual and graphical tools for running tests JUnit distinguishes between failures and errors: A failure is a failed assertion, i.e., an anticipated problem that you test. An error is a condition you didn’t check for.

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.9 The JUnit Framework

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.10 A Testing Scenario The framework calls the test methods that you define for your test cases.

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.11 Example: Testing Set Class: SetTestCase superclass: TestCase instance variable: empty full SetTestCase>>setUp empty := Set new. full := Set with: #abc with: 5 The setUp method specifies the context in which each test is run.

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.12 Testing Set Creation SetTestCase>>testCreation self assert: empty isEmpty. self deny: full isEmpty

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.13 Tests Addition SetTestCase>>testAdd empty add: 5. self assert: (empty includes: 5). SetTestCase>>testAdd empty add: 5. empty add: 5. self assert: (empty includes: 5). full add: 5 self assert: (full size = 2).

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.14 Occurrences and Remove SetTestCase>>testOccurrences self assert: (empty occurrenceOf: 0) = 0. self assert: (full occurrencesOf: 5) = 1. full add: 5. Self assert: (full occurrencesOf: 5) = 1 SetTestCase>>testRemove full remove: 5. self assert: (full includes: #abc). self deny: (full includes: 5)

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.15 Exceptions SetTestCase>>testRemoveNonExistingElement self should: [empty remove: 5] raise: [Error]

© S. Demeyer, S. Ducasse, O. Nierstrasz Chapter.16 Synergy between Tests and Refactorings Tests can cover places where you have to manually change the code  Changing 3 by 33, nil but NewObject new Tests let you been more aggressive to change and improve your code