DOC PREVIEW
DREXEL CS 451 - Dependable Software Systems

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

SoftWindows 9/3/2003Distributed Objects 1Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisDependable Software SystemsTopics in Unit Testing ToolsMaterial drawn from [junit.org, jcoverage.com]Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros Mancoridisjunit 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)Software Engineering (Unit Testing Tools)© Spiros MancoridisDownloading 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 jcoveragedistribution under the lib directory.SoftWindows 9/3/2003Distributed Objects 2Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisImplementation of theSimpleStack classimport 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);}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;}}Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisTesting the SimpleStack classusing a junit StackTest classimport 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 () {s = new SimpleStack(0);assertTrue(s.top() == null);}}Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisRun the StackTest classtest cases in batch modejava junit.textui.TestRunner StackTestOutput:-------Time: 0OK (3 tests)• Compile SimpleStack and StackTest– Don’t forget to set your CLASSPATH.• Then execute the StackTest test cases.– Use batch or GUI modeSoftWindows 9/3/2003Distributed Objects 3Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisRun the StackTest classtest cases in GUI modejava junit.swingui.TestRunner StackTestSoftware Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisCoverage 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)© Spiros MancoridisCoverage 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 VMSoftWindows 9/3/2003Distributed Objects 4Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros Mancoridisjcoveragebyte code instrumentation• java com.jcoverage.coverage.Instrument[-ignore ignore-regex][-d destination-directory][@classlist-file...][classfiles...]• Important options:– -d destination-directoryDirectory where instrumented classes are written. If this isn’t specified, the classes are instrumented in place (overwrite mode). – classfilesSpecifies the list of classes to be instrumented.Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros Mancoridisjcoveragebyte 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)Software Engineering (Unit Testing Tools)© Spiros MancoridisExample invoking the jcoverageInstrumentation programset ICLASSES=c:\Documents and Settings\smancori\Calculator\classesjava 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.jarSoftWindows 9/3/2003Distributed Objects 5Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisjcoverageHTML Report Generation• java com.jcoverage.coverage.reporting.Main[-i instrumentation-file][-o reports-directory][-s java-source-directory]• options:– -i instrumentation-fileThe instrumentation file to generate reports (i.e., jcoverage.ser)– -o reports-directoryDirectory where HTML report is created– -s java-source-directory Directory containing the Java source code.Software Engineering (Unit Testing Tools)Software Engineering (Unit Testing Tools)© Spiros MancoridisjcoverageHTML Report Generation• Generates a multi-page coverage


View Full Document

DREXEL CS 451 - Dependable Software Systems

Download Dependable Software Systems
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Dependable Software Systems and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Dependable Software Systems 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?