Chapter 15: Discovering problems ● There are some tools that we can use to discover problems – Junit: for unit testing – Ant as a make utility – CVS as.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
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.
The Line Class Suppose you are involved in the development of a large mathematical application, and this application needs an object to represent a Line.
Christian Hujer What is AceUnit? How does AceUnit work? How do I use AceUnit? © 2007 Christian Hujer.
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Computer Science 209 Testing With JUnit. Why Test? I don ’ t have time, I ’ ve got a deadline to meet The more pressure I feel, the fewer tests I will.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Integrated Development Environments, Source Control Repositories, Automated Testing Tools, Bug Tracking, Code Analysis Tools, Build Tools, Project Hosting.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
Software Development Tools COMP220/COMP285 Seb Coope Ant and XML: Getting Started These slides are mainly based on “Java Development with Ant” - E. Hatcher.
JAVA BASICS. Why Java for this Project? Its open source - FREE Java has tools that work well with rdf and xml –Jena, Jdom, Saxon Can be run on UNIX,Windows,LINUX,etc.
ANT: Another Nice Tool Ali Beyad October 1, 2003.
ANT – Another Neat Tool Representation and Management of Data on the Internet.
ANT: Another Nice Tool Ali Beyad October 1, 2003.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Classes and Objects: Recap A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Road Map Introduction to object oriented programming. Classes
Processes CSCI 444/544 Operating Systems Fall 2008.
1 Ant – Another Neat Tool Representation and Management of Data on the Internet.
1 Software Testing and Quality Assurance Lecture 23 – JUnit Tutorial.
Fall 2007CS 2251 Programming Tools Eclipse JUnit Testing make and ant.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Using ArrayList. Lecture Objectives To understand the foundations behind the ArrayList class Explore some of the methods of the ArrayList class.
Classes and Objects  A typical Java program creates many objects which interact with one another by sending messages. Through the objects interactions,
Presentation Outline What is JUnit? Why Use JUnit? JUnit Features Design of JUnit Downloading JUnit Writing Tests – TestCase – TestSuite Organizing The.
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
CSE 403 Lecture 11 Static Code Analysis Reading: IEEE Xplore, "Using Static Analysis to Find Bugs" slides created by Marty Stepp
Java 程序设计 Java Programming Fall, Contents for Today Java Program Structure  How to Compile a Java Program  How to Run a Java Program Environment.
Testing. What is Testing? Definition: exercising a program under controlled conditions and verifying the results Purpose is to detect program defects.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Suite zTPFGI Facilities. Suite Focus Three of zTPFGI’s facilities:  zAutomation  zTREX  Logger.
July 2011CMSC 341 CVS/Ant 1 CMSC 341 Java Packages Ant CVS Project Submission.
Suite zTPFGI Facilities. Suite Focus Three of zTPFGI’s facilities:  zAutomation  zTREX  Logger.
Chapter 14 Generics and the ArrayList Class Slides prepared by Rose Williams, Binghamton University Copyright © 2008 Pearson Addison-Wesley. All rights.
Working with arrays (we will use an array of double as example)
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
Unit Testing with JUnit and Clover Based on material from: Daniel Amyot JUnit Web site.
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
Java 3: Odds & Ends Advanced Programming Techniques.
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.
Chapter 1 Introducing Ant. What is ant? Ant is a build tool  Automate the tasks of compiling code, running test, and packaging the results for redistribution.
Eclipse Project. Installing Visit to download a copy for your home computerhttp:// –Get Release version 3.0 (or.
Enterprise Java v090125Dev Env Overview1 Enterprise Java ( ) Development Environment Overview.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
© Spiros Mancoridis Software Engineering (Unit Testing Tools) Dependable Software Systems Topics in Unit Testing Tools Material drawn from [ junit.org,
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.
Today… “Hello World” ritual. Brief History of Java & How Java Works. Introduction to Java class structure. But first, next slide shows Java is No. 1 programming.
Unit, Regression, and Behavioral Testing Based On: Unit Testing with JUnit and CUnit by Beth Kirby Dec 13, 2002 Jules.
CSE 1201 Object Oriented Programming ArrayList 1.
PROGRAMMING TESTING B MODULE 2: SOFTWARE SYSTEMS 22 NOVEMBER 2013.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Classes, Interfaces and Packages
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.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
The need for Programming Languages
Logger, Assert and Invariants
Chapter 2: System Structures
Corresponds with Chapter 5
Presentation transcript:

Chapter 15: Discovering problems ● There are some tools that we can use to discover problems – Junit: for unit testing – Ant as a make utility – CVS as a version control – Logging – Debugging – Profiling

JUnit ● A framework for white-box unit testing ● There is a TestCase class in the framework that we extend to implement our tests ● Each those subclass can contain a number of tests which is implemented as public methods beginning with the word “test” ● Also we can define a setUp() method which is called before each test ● And a tearDown() which is called after each test ● Junit uses reflection to find tests and execute them

A sample Junit test case import junit.framework.*; // So we can see the list objects being created, // and keep track of when they are cleaned up: class CountedList extends ArrayList { private static int counter = 0; private int id = counter++; public CountedList() { System.out.println("CountedList #" + id); } public int getId() { return id; } } public class JUnitDemo extends TestCase { private static com.bruceeckel.simpletest.Test monitor = new com.bruceeckel.simpletest.Test(); private CountedList list = new CountedList(); // You can use the constructor instead of setUp(): public JUnitDemo(String name) { super(name); for(int i = 0; i < 3; i++) list.add("" + i); }

A sample Junit test case (cont.) // Thus, setUp() is optional, but is run right // before the test: protected void setUp() { System.out.println("Set up for " + list.getId()); } // tearDown() is also optional, and is called after // each test. setUp() and tearDown() can be either // protected or public: public void tearDown() { System.out.println("Tearing down " + list.getId()); } // All tests have method names beginning with "test": public void testInsert() { System.out.println("Running testInsert()"); assertEquals(list.size(), 3); list.add(1, "Insert"); assertEquals(list.size(), 4); assertEquals(list.get(1), "Insert"); } public void testReplace() { System.out.println("Running testReplace()"); assertEquals(list.size(), 3); list.set(1, "Replace"); assertEquals(list.size(), 3); assertEquals(list.get(1), "Replace"); }

A sample Junit test case (cont.) // A "helper" method to reduce code duplication. As long private void compare(ArrayList lst, String[] strs) { Object[] array = lst.toArray(); assertTrue("Arrays not the same length", array.length == strs.length); for(int i = 0; i < array.length; i++) assertEquals(strs[i], (String)array[i]); } public void testOrder() { System.out.println("Running testOrder()"); compare(list, new String[] { "0", "1", "2" }); } public void testRemove() { System.out.println("Running testRemove()"); assertEquals(list.size(), 3); list.remove(1); assertEquals(list.size(), 2); compare(list, new String[] { "0", "2" }); } public void testAddAll() { System.out.println("Running testAddAll()"); list.addAll(Arrays.asList(new Object[] { "An", "African", "Swallow"})); assertEquals(list.size(), 6); compare(list, new String[] { "0", "1", "2", "An", "African", "Swallow" }); }

A sample Junit test case (cont.) public static void main(String[] args) { junit.textui.TestRunner.run(JUnitDemo.class); monitor.expect(new String[] { "CountedList #0", "CountedList #1", "CountedList #2", "CountedList #3", "CountedList #4", ".Set up for 0", "Running testInsert()", "Tearing down 0", ".Set up for 1", "Running testReplace()", "Tearing down 1", ".Set up for 2", "Running testOrder()", "Tearing down 2", ".Set up for 3", "Running testRemove()", "Tearing down 3", ".Set up for 4", "Running testAddAll()", "Tearing down 4", "", "% Time:.*", "", "OK (5 tests)", "", }); } } ///:~

Building with ANT ● When a project gets large, it is always needed to automate some tasks. ● Typical tasks are: ● compiling new or updated code ● Packaging class files to a jar file ● Running tests ● Generating java docs ● And so on ● This are the typical tasks that ANT help us to manage easily

Using ANT ● Ant is available for free both in source code and executable form ● It is also integrated into eClipse ● To use ant you need to make a build.xml which contains special instruction for ant ● This is an xml file with special tags and attributes according to ant specifications

Example of a build.xml file <project name="Thinking in Java (c02)" default="c02.run" basedir="."> <javac srcdir="${basedir}" classpath="${basedir}/.." source="1.4" /> <java taskname="HelloDate" classname="HelloDate" classpath="${basedir};${basedir}/.." fork="true" failonerror="true" />

Example of a build.xml file (cont.)

Version control with CVS ● CVS keeps code (and other related files) in a repository in a server ● The server may be a local area networkd or a server on the internet ● Once a CVS server is initialized, team members can get a copy of files on it. If someone connects for the first time, it gets a full copy of all files on the server (current version). However, for later updates he/she gets those that has been updated and also can put his/her update to the server ● If some collisions happens before commiting your changes cvs shows you that and you have the chance to correct them ● Eclipse supports CVS and is very convenient to use

Logging ● We may want to store some useful information during the execution of the program. ● Those information may help us to locate bugs in the code or improve software functionality ● Logging is much better way than inserting println statements into the code ● JDK 1.4 has the logging facility (for previous versions we had to use a framework like “log4j” )

Logging example import java.util.logging.*; public class InfoLogging { private static Test monitor = new Test(); private static Logger logger = Logger.getLogger("InfoLogging"); public static void main(String[] args) { logger.info("Logging an INFO-level message"); monitor.expect(new String[] { "%.* InfoLogging main", "INFO: Logging an INFO-level message" }); }

Log levels

Handlers

Debugging ● A debuuger helps in stepping through the code, execute statements (one by one or continues upto a breakpoint) ● We can display the contents of variables as program proceed ● JDK has JDB as a tool which we can use from command line ● Eclipse has a sophisticated visual debugger which is very convenient to use

Eclipse debugging

Eclipse debugging (stepping inside)

Profiler ● A profiler gathers information that allows you to see which parts of the program consume memory and which methods consume maximum time. ● Memory usage data: ● Number of object allocations for a specific type. ● Places where the object allocations are taking place. ● Methods involved in allocation of instances of this class. Loitering objects: objects that are allocated, not used, and not garbage collected. ● etc.

Profiler (cont.) ● Tracking CPU usage: ● The number of times a method was invoked. ● The percentage of CPU time utilized by each method. ● Total absolute time spent by each method, including the time it waits for I/O, locks, etc. ● JDK ships with a profiler named HPROF which we can use for profiling