Testing code COMP204. How to? “manual” –Tedious, error-prone, not repeatable “automated” by writing code: –Assertions –Junit.

Slides:



Advertisements
Similar presentations
1. Define the concept of assertions. 1 Explain the use of assertions. 2 Create Java program using assertions. 3 Run Java program using assertions. 4 2.
Advertisements

Practice Session 5 Java: Packages Collection Classes Iterators Generics Design by Contract Test Driven Development JUnit.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
JUnit intro Kalvis Apsitis. What are “Programmer Tests”? Programmer Testing is the testing performed by a developer with the goal of verifying the correct.
Objectives: Test Options JUnit Testing Framework TestRunners Test Cases and Test Suites Test Fixtures JUnit.
Testing by Duncan Butler Sara Stephens. Too much to cover.
Testing and Debugging pt.2 Intro to Complexity CS221 – 2/18/09.
More on Functions Programming. COMP104 Lecture 19 / Slide 2 Passing Parameters by Reference l To have a function with multiple outputs, we have to use.
JUnit. Why is testing good? Due to psychological factors, programmers are bad testers. A computer can test much faster than a human Philosophy: “If it.
TDD Test-Driven Development. JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to.
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.
1 Advanced Material The following slides contain advanced material and are optional.
14-Jul-15 JUnit 4. Comparing JUnit 3 to JUnit 4 All the old assertXXX methods are the same Most things are about equally easy JUnit 4 makes it easier.
Programmer Testing Testing all things Java using JUnit and extensions.
Ranga Rodrigo. Class is central to object oriented programming.
Unit Testing & Defensive Programming. F-22 Raptor Fighter.
© Dr. A. Williams, Fall Present Software Quality Assurance – JUnit Lab 1 JUnit A unit test framework for Java –Authors: Erich Gamma, Kent Beck Objective:
Recitation 7 James Wei Professor Peck 2/28/2014. Covered in this Recitation LinkedList practice with JUnit testing Submit through ambient.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Sadegh Aliakbary Sharif University of Technology Spring 2012.
Intoduction to Unit Testing Using JUnit to structure Unit Testing SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
Test automation / JUnit Building automatically repeatable test suites.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
Week81 APCS-AB: Java Unit Testing Information today from “Unit Testing in BlueJ” October 28, 2005.
By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development (TDD)
JUnit Automated Software Testing Framework Advanced Material Paul Ammann & Jeff Offutt
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Debugging COMP T1.
JUnit SWE 619 Summer July 18, 2007 SWE 619 (c) Aynur Abdurazik 2 What is JUnit? Open source Java testing framework used to write and run repeatable.
© Spiros Mancoridis Software Engineering (Unit Testing Tools) Dependable Software Systems Topics in Unit Testing Tools Material drawn from [ junit.org,
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved.
2-1 By Rick Mercer with help from Kent Beck and Scott Ambler Java Review via Test Driven Development.
CS-2852 Data Structures LECTURE 7B Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com.
Unit Testing. F-22 Raptor Fighter Manufactured by Lockheed Martin & Boeing How many parts does the F-22 have?
Unit Testing by Jon Edgar. Structure of Presentation Structure What is Unit Testing? Worked Example Extreme Programming (XP) Implementation Limitation.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Reasoning and Design (and Assertions). How to Design Your Code The hard way: Just start coding. When something doesn’t work, code some more! The easier.
Testing It is much better to have a plan when testing your programs than it is to just randomly try values in a haphazard fashion. Testing Strategies:
Testing Technion – Institute of Technology Author: Gal Lalouche © 1 Author: Gal Lalouche - Technion 2016 ©
Test automation / JUnit Building automatically repeatable test suites.
Automated Testing with PHPUnit. How do you know your code works?
CSE 143 Lecture 14: testing.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Unit Testing.
Software Construction Lab 10 Unit Testing with JUnit
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
This presentation is created for the course COP4331 at UCF
More JUnit CS 4501 / 6501 Software Testing
CSE 374 Programming Concepts & Tools
Unit testing C# classes
Junit with.
JUnit Automated Software Testing Framework
JUnit 28-Nov-18.
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Credit to Eclipse Documentation
Introduction to JUnit CS 4501 / 6501 Software Testing
Advanced Programming Behnam Hatami Fall 2017.
Introduction to JUnit IT323 – Software Engineering II
Test Driven Development
Testing Acknowledgement: Original slides by Jory Denny.
Test Driven Development
Go to pollev.com/cse143.
CSE 143 Lecture 5 More ArrayIntList:
JUnit Reading: various web pages
CSE 1020:Software Development
Unit Testing.
Presentation transcript:

Testing code COMP204

How to? “manual” –Tedious, error-prone, not repeatable “automated” by writing code: –Assertions –Junit

Assertions “manually” if (! check()) { throw new RuntimeException(“…”); } Better: use “assert” command assert check(); Will only be checked if enabled: -ea assert check42(a) : “check42 failed for “ + a ;

Assertions continued Use in methods to check preconditions: assert (parameter1 != null); Or post-conditions before returning: assert (stack.size() == oldSize+1); Or class-invariants at the start and end of public methods: assert integrity();

Junit Unit testing implements tests for “units” in separate classes that usually mirror the original class structure: –BoundedStack.java –BoundedStackTest.java

Unit tests Check all public methods Can even be used as specifiation (e.g. in TDD - test driven development), written *before* the code they test Run after a every code change Have someone else write unit tests

Junit import static org.junit.Assert.*; assertEquals(a,b); assertArrayEquals(x,y); … Annotations: = RuntimeException.class) = 100)

How good are the tests Code coverage: –Is every line executed at least once? –Borderline cases (e.g. +/- 1) public int sumAndSort(Integer[] a) { int sum = 0; for(Integer e: a) sum += e; Arrays.sort(a); return sum; }

Two different “full cover” tests public void someTest() { assertEquals(6, sumAndSort(new Integer[]{3,1,2})); } public void betterTest() { Integer[] a = new Integer[]{3,1,2}; assertEquals(6, sumAndSort(a)); assertArrayEquals(new Integer[]{1,2,3}, a); }

Jumble: mutation testing Open source, Honour’s project of Tin Pavlinic, supervised by Prof.John Cleary (ReelTwo), a few years ago Mutates the byte-code of a class, then checks whether the unit-tests pick up the changes