JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools.
Advertisements

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
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.
Processing and Java David Meredith
Developing in CAS. Why? As distributed you edit CAS 3 with Eclipse and build with Maven 2 – Best Practice for Release Engineering – Difficult edit-debug.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
® IBM Software Group © 2010 IBM Corporation What’s New in Profiling & Code Coverage RAD V8 April 21, 2011 Kathy Chan
T ESTING WITH J UNIT IN E CLIPSE Farzana Rahman. I NTRODUCTION The class that you will want to test is created first so that Eclipse will be able to find.
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.
Ch. 2 Exploring core JUnit. This chapter covers ■ Using the core JUnit classes ■ Understanding JUnit mechanisms ■ Understanding the JUnit lifecycle.
JUnit Automated Software Testing Framework Paul Ammann & Jeff Offutt Thanks in part to Aynur Abdurazik.
Java Integrated Development Environments: ECLIPSE Part1 Installation.
JUnit, Revisited 17-Apr-17.
Delta Debugging - Demo Presented by: Xia Cheng. Motivation Automation is difficult Automation is difficult fail analysis needs complete understanding.
Integrated Development Environments. Today We Will: Discuss what IDE’s are used for Go over the Eclipse IDE: –What is Eclipse? –How to install and set.
Guide To UNIX Using Linux Third Edition
Unit testing C# classes “If it isn’t tested it doesn’t work” Unit testing C# classes1.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
George Blank University Lecturer. JUnit for Test Driven Development By Vivek Bhagat, George Blank.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Eclipse IDE. 2 IDE Overview An IDE is an Interactive Development Environment Different IDEs meet different needs BlueJ and DrJava are designed as teaching.
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:
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Comp 249 Programming Methodology Chapter 8 - Polymorphism Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal,
Computer Science and Engineering College of Engineering The Ohio State University JUnit The credit for these slides goes to Professor Paul Sivilotti at.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
Week 4 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Installing Repast in the Eclipse IDE Charlie Gieseler 6/28/04.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
SilkTest 2008 R2 SP1: Silk4J Introduction. ConfidentialCopyright © 2008 Borland Software Corporation. 2 What is Silk4J? Silk4J enables you to create functional.
Tool Install How to download & install Java 6 & Eclipse updated version based on Dr. G. L. Ray’s slides.
Software Development COMP220/COMP285 Seb Coope Introducing Ant These slides are mainly based on “Java Development with Ant” - E. Hatcher & S.Loughran.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
JUnit Jumpstart © Manning Publications.
Scalatest. 2 Test-Driven Development (TDD) TDD is a technique in which you write the tests before you write the code you want to test This seems backward,
JUnit. Introduction JUnit is an open source Java testing framework used to write and run repeatable tests JUnit is integrated with several IDEs, including.
Surya Bahadur Kathayat Outline  Ramses  Installing Ramses  Ramses Perspective (Views and Editors)  Importing/Exporting Example.
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.
All the dSoftArk Tools Getting started!. Tools dSoftArk is a semi-realistic, agile, development project –Industrial strength software (programming, TDD,
Test Automation Using Selenium Presented by: Shambo Ghosh Ankit Sachan Samapti Sinhamahapatra Akshay Kotawala.
Time to apply stuff… Faculty of Mathematics and Physics Charles University in Prague 5 th October 2015 Workshop 1 – Java Wrestling.
Software Design– Unit Testing SIMPLE PRIMER ON Junit Junit is a free simple library that is added to Eclipse to all automated unit tests. The first step,
Netbeans QuickStart. Creating a project File->New Project –For now you want General->Java Application –Then fill in the project details.
Unit Testing in Eclipse Presented by David Eisler 08/09/2014.
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
Java IDE Dwight Deugo Nesa Matic
Required Tools Copyright © 2005 Liferay, LLC All Rights Reserved. No material may be reproduced electronically or in print without written permission from.
SWE 434 SOFTWARE TESTING AND VALIDATION LAB2 – INTRODUCTION TO JUNIT 1 SWE 434 Lab.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Unit Testing.
Software Construction Lab 10 Unit Testing with JUnit
JUnit Automated Software Testing Framework
Introduction to JUnit CS 4501 / 6501 Software Testing
Introduction to Python
Test-driven development (TDD)
Introduction to JUnit CS 4501 / 6501 Software Testing
Testing Acknowledgement: Original slides by Jory Denny.
CS 240 – Advanced Programming Concepts
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
CMPE212 – Reminders Assignment 2 due today, 7pm.
JUnit Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from the Eclipse 3.0 and.
Junit Tests.
Workshop for Programming And Systems Management Teachers
Plug-In Architecture Pattern
JUnit Tutorial Hong Qing Yu Nov 2005.
Presentation transcript:

JUnit in Action SECOND EDITION PETAR TAHCHIEV FELIPE LEME VINCENT MASSOL GARY GREGORY ©2011 by Manning Publications Co. All rights reserved. Slides Prepared by: Dr. Samer Hanna

Needed downloads to run this book’s tests 1) Java 2 Standard Edition JDK Current version is JDK 6 update 22 2) Eclipse IDE Note: Eclipse documentation is available at:

PART 1 JUNIT ESSENTIALS Ch. 1 ■ JUnit jump-start Ch. 2 ■ Exploring core JUnit Ch. 3 ■ Mastering JUnit Ch. 4 ■ Software testing principles

Ch1. JUnit jump-start This chapter covers ■ Exploring JUnit ■ Installing JUnit ■ Writing our first test ■ Running tests

Introduction JUnit ( is open source software released under IBM’s Common Public License Version 1.0 and hosted on SourceForge JUnit quickly became the de facto standard framework for developing unit tests in Java. DEFINITION A unit test examines the behavior of a distinct unit of work. Within a Java application, the “distinct unit of work” is often (but not always) a single method.

Cont. By contrast, integration tests and acceptance tests examine how various components interact. A unit of work is a task that isn’t directly dependent on the completion of any other task.

Setting up JUnit In order to use JUnit to write your application tests, you need to add the JUnit JAR file to your project’s compilation classpath and to your execution classpath. Follow these steps: Download the JUnit distribution (junit-4.10 or newer) from Unzip the distribution zip file to a directory on your computer system In this directory, unzipping will create a subdirectory for the JUnit distribution you downloaded (for example, C:\junit4.6)

Adding junit-4.6.jar to our external jar files using Eclipse To run all the examples in this book we should tell Eclipse where it can find the junit-4.6.jar (or later) jar file and this is done by the following steps: Go to project menu Choose properties Choose Java Build Path Choose Add External Jars A Jar Selection window will be opened and you can browse to the folder where the junit-4.10.jar file is stored and select this file. Now you are ready to use JUnit

Testing with JUnit Example

The JUnit CalculatorTest program

CalculatorTest details At 1, we start by defining a test class. The only restriction is that the class must be public; we can name it whatever we like. It’s common practice to end the class name with Test. At 2, we mark the method as a unit test method by adding annotation. A best practice is to name test methods following the testXXX pattern.

Cont. JUnit doesn’t have method name restrictions. You can name your methods as you like; as long as they have annotation, JUnit will execute them. At 3, we start the test by creating an instance of the Calculator class (the “object under test”). At 4, as before, we execute the test by calling the method to test, passing it two known values. At 5, the JUnit framework begins to shine! To check the result of the test, we call an assertEquals method, which we imported with a static import on the first line of the class

assertEquals method The Javadoc for the assertEquals method is as follows: /** * Asserts that two doubles or floats are equal to within a positive delta. */ static public void assertEquals( double expected, double actual, double delta)

In the previous example, we passed assertEquals these parameters: expected = 60 actual = result delta = 0

Because we passed the calculator the values 10 and 50, we tell assertEquals to expect the sum to be 60. (We pass 0 as the delta because we’re adding integers.) When we called the calculator object, we tucked the return value into a local double named result. Therefore, we pass that variable to assertEquals to compare against the expected value of 60.

Cont. If the actual value isn’t equal to the expected value, JUnit throws an unchecked exception, which causes the test to fail. Most often, the delta parameter can be zero, and we can safely ignore it. It comes into play with calculations that aren’t always precise, which includes many floating point calculations. The delta provides a range factor. If the actual value is within the range expected - delta and expected + delta, the test will pass.

Summary Every developer should perform some type of test to see if code works. Developers who use automatic unit tests can repeat these tests on demand to ensure that new code works and doesn’t break existing tests. Simple unit tests aren’t difficult to create without JUnit, but as tests are added and become more complex, writing and maintaining tests becomes more difficult. JUnit is a unit testing framework that makes it easier to create, run, and revise unit tests.

Summary (Cont.) In this chapter, we scratched the surface of JUnit by stepping through a simple test. JUnit has much more to offer. In chapter 2 we take a closer look at the JUnit framework classes (different annotations and assertion mechanisms) and how they work together to make unit testing efficient and effective.