JUnit Jumpstart © 2003-2004 Manning Publications.

Slides:



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

Java Testing Tools. junit is a testing harness for unit testing. emma is a code coverage tool. The tools can be used in concert to provide statement and.
J-Unit Framework.
An Introduction to JUnit Greg Jackson June Software Quality Assurance & Testing 2 Contact Info Northrop Grumman Corp
Unit and Functional Testing with JUnit and Related Tools Greg Barnes University of Washington
Ch. 2 Exploring core JUnit. This chapter covers ■ Using the core JUnit classes ■ Understanding JUnit mechanisms ■ Understanding the JUnit lifecycle.
Approach of Unit testing with the help of JUnit Satish Mishra
Stacks.
S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
JUnit Syed Nabeel. Motivation Unit Testing Responsibility of  developer Rarely done properly Developers Excuse: “I am too much in a hurry”
JUnit, Revisited 17-Apr-17.
22-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.
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.
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.
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.
Struts 2.0 an Overview ( )
CSE219, Computer Science III Stony Brook University Test-Driven Development (a.k.a. Design to Test) 1.
Lesson 7 Unit Testing /JUnit/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
Junit Training Chris Yeung 8 th Sept, Introduction JUnit is a regression testing frameworkJUnit is a regression testing framework Written by Erich.
JUnit The framework. Goal of the presentation showing the design and construction of JUnit, a piece of software with proven value.
Principles of Object Oriented Programming Practical session 2 – part A.
Methods and You. Up to this point, I have covered many different data types with you. Variables can be considered the nouns of an English sentence. If.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.
Automated GUI testing How to test an interactive application automatically?
Introduction to Testing 1. Testing  testing code is a vital part of the development process  the goal of testing is to find defects in your code  Program.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
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.
Junit At the forefront of Test Driven Development.
Well-behaved objects Main concepts to be covered Testing Debugging Test automation Writing for maintainability Objects First with Java - A Practical.
Plug-In Architecture Pattern. Problem The functionality of a system needs to be extended after the software is shipped The set of possible post-shipment.
Introduction to JUnit 3.8 SEG 3203 Winter ‘07 Prepared By Samia Niamatullah.
ESO - Garching 23 June – 02 July, 2003 ACS Course JUnit for Java Unit Testing H. Sommer.
Week81 APCS-AB: Java Unit Testing Information today from “Unit Testing in BlueJ” October 28, 2005.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
JUnit Don Braffitt Updated: 10-Jun-2011.
Iteration 1 Looping Structures. Iteration 2 The Plan While not everyone understands: 1.Motivate loops 2.For loops 3.While loops 4.Do-while loops 5.Equivalence.
JUnit Eclipse, Java and introduction to Junit. Topics Covered  Using Eclipse IDE  Example Java Programs  Junit Introduction.
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.
1 Unit testing and Java Zeger Hendrikse Cas Stigter.
© 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.
1 Unit Testing with JUnit CS 3331 JUnit website at Kent Beck and Eric Gamma. Test Infected: Programmers Love Writing Tests, Java Report,
JUnit A Unit Testing Framework for Java. The Objective Introduce JUnit as a tool for Unit Testing Provide information on how to: Install it Build a test.
JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved.
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.
1 JUnit. 2 Unit Testing with JUnit If code has no automated test case written for it to prove that it works, it must be assumed not to work. An API that.
1 Lecture 15 Remote Method Invocation Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Testing PA165 Dec 9, 2014 Petr Adámek, Tomáš Pitner.
JUnit Tatiana Totskaya. Main parts of the presentation  Unit Testing  JUnit – Main Concepts  JUnit Primer  Unit Testing in Eclipse Using JUnit.
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.
JUnit Automated Software Testing Framework
Computer Science 209 Testing With JUnit.
JUnit Automated Software Testing Framework
Selenium HP Web Test Tool Training
Mocking Your Objects with Impunity
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
SOEN 343 Software Design Computer Science and Software Engineering Department Concordia University Fall 2004 Instructor: Patrice Chalin.
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to JUnit IT323 – Software Engineering II
Joel Adams and Jeremy Frens Calvin College
Java Remote Method Invocation
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
JUnit Tutorial Hong Qing Yu Nov 2005.
Principles of Object Oriented Programming
Presentation transcript:

JUnit Jumpstart © Manning Publications

JUnit Jumpstart Writing simple tests by hand Writing better tests with JUnit Installing JUnit and running tests

About Vincent Massol Lead author, JUnit Action Committer, Jakarta Catcus testing framework Committer, SourceForge MockObjects project Co-founder and CTO of Pivolis, Paris

About Ted Husted Co-author, JUnit in Action Member, Apache Software Foundation Jakarta Struts Committer Working developer Training and mentoring

Proving it works “All code is tested.” Play tests Step-thru tests Test programs

Starting from scratch public class Calculator { public double add( double number1, double number2) { return number1 + number2; }

Calculator Responsibilities add method – Take two doubles and return the sum as a double. subtract method – TODO multiply method – TODO divide method – TODO …

“Too simple to break?” JUnit practice: “Test anything that’s not too simple to break.” Is this implementation of add is too simple to break? Yes, but future implementations may not be Beck: “Any program feature without an automated test doesn’t exist.”

Proving it works “All code is tested.” Play tests Step-thru tests Test programs

Proving it works “All code is tested.” Play tests Step-thru tests Test programs

Proving it works “All code is tested.” Play tests Step-thru tests Test programs

Why write test programs?

Code under test public class Calculator { public double add( double number1, double number2) { return number1 + number2; }

Proving add works public class TestCalculator { public static void main(String[] args) { Calculator calculator = new Calculator(); double result = calculator.add(10,50); if (result != 60) { System.out.println("Bad result: " + result); }

Too simple to be useful? Test is fine, as far as it goes Infrastructure poor Need to add more tests Need automatic monitoring Testing program, not ourselves

A better infrastructure public class TestCalculator { public static void main(String[] args) { TestCalculator test = new TestCalculator(); try { test.testAdd(); //... More tests here... } catch (Throwable e) { errors++; e.printStackTrace(); } if (test.errors > 0) { throw new RuntimeException("There were " + test.errors + " error(s)"); }

A better infrastructure private int errors = 0; public void testAdd() { Calculator calculator = new Calculator(); double result = calculator.add(10, 50); if (result != 60) { throw new RuntimeException("Bad result: " + result); } //... more tests here... }

Scratch Test public class TestCalculator { public static void main(String[] args) { Calculator calculator = new Calculator(); double result = calculator.add(10,50); if (result != 60) { System.out.println("Bad result: " + result); }

Testing with JUnit import junit.framework.TestCase; public class TestCalculator extends TestCase { public void testAdd() { Calculator calculator = new Calculator(); double result = calculator.add(10, 50); assertEquals(60, result, 0); } //... more test* methods here... }

Programmer’s Unit Test A programmer’s unit test examines the behavior of a distinct “unit of work”. In a Java application, methods often represent units of work. By contrast, integration and acceptance tests examine component interactions.

IEEE Unit Test “Testing of individual hardware or software units or groups of related units.” (emphasis added)

Unit of Work A task that is not dependant on the completion of any other task.

API Contact A view of an Application Programming Interface (API) as a formal agreement between the caller and the callee.

JUnit Goals Each unit test must run independently of all other unit tests Errors must be detected and reported test-by-test It must be easy to define which unit tests will run

JUnit Goals The framework must help us write useful tests create tests that retain value lower costs by reusing code

JUnit Today Junit – Gama and Beck, 1997 Framework – semi complete application xUnit frameworks: C#, Perl, PHP, Visual Basic, et al Website:

Setting up JUnit Download from junit.org Unzip distribution c:\junit /opt/JUnit /opt/Maven/junit/releases

Testing JUnit Windows: java -cp junit.jar;. junit.textui.TestRunner junit.samples.AllTests UNIX: java -cp junit.jar:. junit.textui.TestRunner junit.samples.AllTests

Testing JUnit

To run the text test runner, open a shell in C:\junit\junit3.8.1 on Windows or in /opt/junit\junit3.8.1 on UNIX, and type the appropriate command: Windows: java -cp junit.jar;. junit.swingui.TestRunner junit.samples.AllTests UNIX: java -cp junit.jar:. junit.swingui.TestRunner junit.samples.AllTests

Summary o We all test the code we write o Simple test programs are simple o JUnit makes testing even simpler o JUnit preserves our investment in testing o “Test until fear turns to boredom”

JUnit in Action JUnit Distilled JUnit Jumpstart Exploring JUnit Sampling JUnit Examining software tests Automating JUnit

JUnit in Action Testing Strategies Coarse-grained testing with stubs Testing in isolation with mock objects In-container testing with Cactus

JUnit in Action Testing Components Unit-testing servlets and filters Unit-testing JSPs and taglibs Unit-testing database applications Unit-testing EJBs