Dependable Software Systems

Slides:



Advertisements
Similar presentations
Design By Contract Using JMSAssert.
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.
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
J-Unit Framework.
MAHDI OMAR JUNIT TUTORIAL. CONTENTS Installation of Junit Eclipse support for Junit Using Junit exercise JUnit options Questions Links and Literature.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods 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.
Maven & Bamboo CONTINUOUS INTEGRATION. QA in a large organization In a large organization that manages over 100 applications and over 20 developers, implementing.
Coverage tools Program is typically compiled with special options, to add extra source or object code. –Additional data structures, such as a flow graph,
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
CSC Java Programming, Fall, 2008 Week 2: Java Data Types, Control Constructs, and their C++ counterparts, September 4.
POS 406 Java Technology And Beginning Java Code
CSC 216/001 Lecture 4. Unit Testing  Why is it called “unit” testing?  When should tests be written?  Before the code for a class is written.  After.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
The quick fact of EMMA Seiya Kawashima Loyola University Chicago EMMA:Copyright © Vlad Roubtsov All rights reserved.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
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.
Testing code COMP204. How to? “manual” –Tedious, error-prone, not repeatable “automated” by writing code: –Assertions –Junit.
© 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 CSC 216 Lecture 3. 2 Unit Testing  The most basic kind of testing is called unit testing  Why is it called “unit” testing?  When should tests be.
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.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
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.
Topic: Junit Presenters: Govindaramanujam, Sama & Jansen, Erwin.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
© Dr. A. Williams, Fall Present Software Quality Assurance – Clover Lab 1 Tutorial / lab 2: Code instrumentation Goals of this session: 1.Create.
CS320 Web and Internet Programming Introduction to Java Servlets Chengyu Sun California State University, Los Angeles.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
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.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Jester – The JUnit Test Tester
Software Construction Lab 10 Unit Testing with JUnit
5/9/2018 Advanced Unit Testing David Rabinowitz.
Working with Java.
JUnit Automated Software Testing Framework
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Computer Science 209 Testing With JUnit.
CompSci 230 Software Construction
Important terms Black-box testing White-box testing Regression testing
Important terms Black-box testing White-box testing Regression testing
JUnit Automated Software Testing Framework
An Introduction to Java – Part I, language basics
Test-driven development (TDD)
Chapter 1: Computer Systems
Overview Unit testing Building Version control.
Applying OO Concepts Using Java
Introduction to javadoc
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Java Code Coverage Tools - EclEmma and JaCoCo
In this class, we will cover:
Joel Adams and Jeremy Frens Calvin College
The for-statement.
JUnit SWE 619 Spring 2008.
CMPE212 – Reminders Assignment 2 due today, 7pm.
Paul Ammann & Jeff Offutt
Corresponds with Chapter 5
Chapter 20: Software Testing - Using JUnit, and Cobertura
Workshop for Programming And Systems Management Teachers
JUnit Tutorial Hong Qing Yu Nov 2005.
Presentation transcript:

Dependable Software Systems 11/17/2018 Dependable Software Systems Topics in Unit Testing Tools Material drawn from [junit.org, jcoverage.com] Software Engineering (Unit Testing Tools)

Software Engineering (Unit Testing Tools) junit and jcoverage We will use a combination of two tools to test Java programs: junit is a unit testing tool jcoverage is a statement/branch coverage tool Both tools are available for free from the WWW. jcoverage has its own testing tool (jtestrun) but we will use junit as a testing harness. junit is included in the jcoverage distribution. Software Engineering (Unit Testing Tools)

Downloading the Software Download junit from: www.junit.org Download jcoverage from: www.jcoverage.com Set your Java CLASSPATH to include: jcoverage.jar, junit.jar, log4j.jar, bcel.jar, jakarta-oro.jar, java-getopt.jar junit.jar, log4j.jar, bcel.jar, jakarta-oro.jar, java-getopt.jar are in the jcoverage distribution under the lib directory. Software Engineering (Unit Testing Tools)

Implementation of the SimpleStack class public Object pop () { Object top = null; if (s != null && s.size() != 0) { top = s.elementAt(s.size()-1); s.removeElementAt(s.size()-1); } return top; public Object top () { Object o = null; if (s != null && s.size() != 0) o = s.elementAt(s.size()-1); return o; import java.util.Vector; class SimpleStack { private Vector s = null; public SimpleStack (int initSize) { s = new Vector(initSize); } public void push (Object o) { s.addElement(o); Software Engineering (Unit Testing Tools)

Testing the SimpleStack class using a junit StackTest class import junit.framework.*; import java.util.Vector; public class StackTest extends TestCase { private SimpleStack s; public static void main (String args[]) { junit.textui.TestRunner.run (suite()); } public static Test suite() { return new TestSuite(StackTest.class); protected void setUp() { s = new SimpleStack(100); public void testPushOne() { s = new SimpleStack(100); String hiString = new String("Hi"); s.push(hiString); assertTrue(s.top() == hiString); System.out.println(hiString); } public void testPopEmpty () { s = new SimpleStack(0); Object o = s.pop(); assertTrue(o == null); public void testTopEmpty () { assertTrue(s.top() == null); Software Engineering (Unit Testing Tools)

Run the StackTest class test cases in batch mode Compile SimpleStack and StackTest Don’t forget to set your CLASSPATH. Then execute the StackTest test cases. Use batch or GUI mode java junit.textui.TestRunner StackTest Output: ------- Time: 0 OK (3 tests) Software Engineering (Unit Testing Tools)

Run the StackTest class test cases in GUI mode java junit.swingui.TestRunner StackTest Software Engineering (Unit Testing Tools)

Software Engineering (Unit Testing Tools) Coverage Tools Tools like jcoverage can be used to determine the degree of comprehensiveness of a test suite. This is important because a test suite may have many test cases, but may only cover a small percentage of the source code. Covering all source statements doesn’t guarantee much, but NOT covering them is a sign of trouble. Software Engineering (Unit Testing Tools)

Software Engineering (Unit Testing Tools) Coverage Analyzers Coverage analyzers must instrument the code to keep track of which statements are executed. Code instrumentation for Java programs can be done in various ways: Modify the source code Modify the byte code (what jcoverage does) Modify the Java VM Software Engineering (Unit Testing Tools)

jcoverage byte code instrumentation java com.jcoverage.coverage.Instrument [-ignore ignore-regex][-d destination-directory] [@classlist-file...][classfiles...] Important options: -d destination-directory Directory where instrumented classes are written. If this isn’t specified, the classes are instrumented in place (overwrite mode). classfiles Specifies the list of classes to be instrumented. Software Engineering (Unit Testing Tools)

jcoverage byte code instrumentation The instrumentation program generates a new version of each class. It is good practice to save the new versions of the bytecode in a separate directory. Don’t instrument instrumented bytecode. The instrumentation program generates a jcoverage.ser file. Don’t delete this file before you execute the instrumented code. The file contains a integer entry for each line of code that is incremented when the code gets executed (tested). Software Engineering (Unit Testing Tools)

Example invoking the jcoverage Instrumentation program set ICLASSES=c:\Documents and Settings\smancori\Calculator\classes java com.jcoverage.coverage.Instrument -d "%ICLASSES%" *.class Execute this code from the directory that contains the bytecode of the program. The instrumented bytecode will be placed in the location specified in the ICLASSES environment variable. Make sure that the following programs are in your CLASSPATH environment variable: log4j.jar - bcel.jar jcoverage.jar - jakarta-oro.jar, junit.jar - java-getopt.jar Software Engineering (Unit Testing Tools)

jcoverage HTML Report Generation java com.jcoverage.coverage.reporting.Main [-i instrumentation-file][-o reports-directory] [-s java-source-directory] options: -i instrumentation-file The instrumentation file to generate reports (i.e., jcoverage.ser) -o reports-directory Directory where HTML report is created -s java-source-directory Directory containing the Java source code. Software Engineering (Unit Testing Tools)

jcoverage HTML Report Generation Generates a multi-page coverage report in HTML from an instrumentation file. Statement coverage percentage Branch coverage percentage Bar-chart visualization used The report has links to HTML versions of the source code: Highlighted statements that were not executed. Hit counts for statements that were executed multiple times. Software Engineering (Unit Testing Tools)

HTML Coverage Report Statement & Branch Coverage Software Engineering (Unit Testing Tools)

HTML Coverage Report Source Code Annotations Software Engineering (Unit Testing Tools)

Example invoking the jcoverage HTML Report Generation program set SERFILE=c:\Documents and Settings\smancori\Calculator\jcovarage.ser set SRCFILES=c:\Documents and Settings\smancori\Calculator set OUTFILES=c:\Documents and Settings\smancori\Calculator\doc java com.jcoverage.coverage.reporting.Main -i “%SERFILE%” -o “%OUTFILE” –s “%SRCFILES%” Execute this program from any directory. The HTML files for the report will be placed in the location specified by OUTFILES. SERFILE directs the program to the instrumentation file (i.e., jcoverage.jar) Software Engineering (Unit Testing Tools)

jcoverage XML Report Generation java com.jcoverage.coverage.reporting.xml.Main [-i instrumentation-file][-o reports-directory] [-s java-source-directory] options: -i instrumentation-file The instrumentation file to generate reports (i.e., jcoverage.ser) -o reports-directory Directory where HTML report is created -s java-source-directory Directory containing the Java source code. Software Engineering (Unit Testing Tools)

jcoverage Merge Instrumentation program java com.jcoverage.tool.merge.Main [-i instrumentation-file …] [-o destination-directory] options: -i instrumentation-file … The two or more instrumentation files to merge into a unified instrumentation file (i.e., jcoverage.ser) -o destination-directory Directory where the unified instrumentation file is created. Software Engineering (Unit Testing Tools)

jcoverage Merge Instrumentation program Merges two or more instrumentation files into a single instrumentation file. A single integrated report can be created from multiple coverage runs. The integrated report can then be fed to the Report Generation program to produce an integrated report. Software Engineering (Unit Testing Tools)

Example invoking the jcoverage Merge Instrumentation program set MERGESERDIR=c:\Documents and Settings\smancori\Calculator java com.jcoverage.tool.merge.Main -i "T1\jcoverage.ser" –i "T2\jcoverage.ser" -i "T3\jcoverage.ser" -o "%MERGESERDIR% Execute this program from the parent directory of the directories containing the jcoverage.ser files to be merged. The merged jcoverage.ser file will be created in the location specified by MERGESERDIR. Software Engineering (Unit Testing Tools)

Software Engineering (Unit Testing Tools) References jcoverage site: www.jcoverage.com junit site: www.junit.org Software Engineering (Unit Testing Tools)