public class

JUnit, Bugzilla
James Atlas
July 24, 2008
*part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL
Review
• Reflection API
• JDBC/Hibernate
• Distributed Programming/RMI
July 24, 2008
James Atlas - CISC370
2
Today
• Software testing
 JUnit
 Mantis
• An important part of all software develoment
processes
July 24, 2008
James Atlas - CISC370
3
Software Development Processes
• Models
 Waterfall (sequential steps)
1.
2.
3.
4.
5.
6.
7.
July 24, 2008
Requirements specification (AKA Verification)
Design
Construction (AKA implementation or coding)
Integration
Testing and debugging (AKA validation)
Installation (AKA deployment)
Maintenance
James Atlas - CISC370
4
Software Development Processes
• Models (cont’)
 Agile (iterative steps)
1.
2.
3.
•
July 24, 2008
Develop tests
Implementation/coding
Design/refactoring
Direct feedback/communication between
customer and software developer
James Atlas - CISC370
5
Software Testing
• Simple/naïve methods
 debugger
 printed output
• How should we go about testing our code?
July 24, 2008
James Atlas - CISC370
6
Software Testing
• Simple/naïve methods
 debugger
 printed output
• How should we go about testing our code?
 automation!
July 24, 2008
James Atlas - CISC370
7
Software Testing
• Unit
 per module testing
 ensures components interact appropriately
• System
 system works in realistic environment
• User Acceptance
 system supports the business for which it was
designed
July 24, 2008
James Atlas - CISC370
8
JUnit
•
•
•
•
•
What is JUnit?
Where Does it Come From?
Working with TestCases
Working with TestSuites
JUnit Window
July 24, 2008
James Atlas - CISC370
9
What is JUnit?
•
•
•
•
•
Regression testing framework
Written by Erich Gamma and Kent Beck
Used for unit testing in Java
Open Source
Released under IBM's CPL
July 24, 2008
James Atlas - CISC370
10
Where Does JUnit Come From?
• JUnit’s web site: http://junit.org/index.htm
• Eclipse includes JUnit
 Eclipse provides new GUI to run JUnit test cases
and suites
• You can run your unit tests outside of Eclipse
 If you wish using TestRunner
 Using JUnit’s Window
July 24, 2008
James Atlas - CISC370
11
Eclipse JUnit Setup
• Eclipse preferences
•
•
can be set in the JUnit
Preferences window
For the most part you
can leave these alone
Filters needed to
identify packages,
classes, or patterns
that should not be
shown in the stack
trace of a test failure
July 24, 2008
James Atlas - CISC370
12
JUnit Test Cases
• Test case
 Runs multiple tests
• Implemented a subclass of TestCase
• Define instance variables that store the state
of the tests in the class
• Initialize TestCase by overriding setUp
method
• Clean-up after test case is done by
overriding tearDown method
July 24, 2008
James Atlas - CISC370
13
Creating TestCases in Eclipse…
• Create a new package to contain your test case classes
• Add the JUnit JAR file to the project’s buildpath
• Or, will be done for you the first time you build a test case
July 24, 2008
James Atlas - CISC370
14
…Creating TestCases in Eclipse
• Select your testing
•
•
•
package
From the context menu
select New  JUnit Test
Case
In the next Window fill
in the name of your test
case
This will create the
corresponding class in
your testing package
July 24, 2008
James Atlas - CISC370
15
TestCase Template
package com.espirity.course.testing;
import junit.framework.TestCase;
public class FirstTestCase extends TestCase {
public FirstTestCase(String arg0) {
super(arg0);
}
public static void main(String[] args) {
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
}
July 24, 2008
James Atlas - CISC370
16
Adding Tests to TestCases
• Any method in a TestCase class is
considered a test if it begins with the word
test
 You can write many tests (have many test
methods)
• Each test method should use a variety of
assert methods to test things about the state
of their classes under tests
 Assert methods are inherited
July 24, 2008
James Atlas - CISC370
17
Assert Methods
• Assert methods include:
 assertEqual(x,y)
 assertFalse(boolean)
 assertTrue(boolean)
 assertNull(object)
 assertNotNull(object)
 assertSame(firstObject, secondObject)
 assertNotSame(firstObject, secondObject)
July 24, 2008
James Atlas - CISC370
18
Adding Two Tests to TestCase
package testing;
import junit.framework.TestCase;
public class FirstTestCase extends TestCase {
public FirstTestCase(String arg0) {
super(arg0);
}
public static void main(String[] args) {}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testCompareSucceed() {
assertEquals(0, 0); //this assertion will succeed
}
public void testCompareFail() {
assertEquals(0, 1); //this assertion will fail
}
}
July 24, 2008
James Atlas - CISC370
19
Running TestCase
• Select TestCase class
• From the Run menu
select Run  Run As 
JUnit Test
• This will run the tests in
•
your TestCase class
along with the setup
and teardown methods
You will then get a
report in the JUnit
Window
July 24, 2008
James Atlas - CISC370
20
JUnit Window…
• Red indicates a
•
•
•
test has failed
If you wish to
see the tests in
TestCase click on
the Hierarchy tab
You can see
which test failed
You can see the
call trace leading
to the failure
July 24, 2008
James Atlas - CISC370
21
…JUnit Window
• You can see how many
•
•
•
tests ran
Errors occur when
exceptions are thrown
How many failures
occurred
You can see the details
of the failure
July 24, 2008
James Atlas - CISC370
22
Creating JUnit TestSuite…
• Test Suite
•
•
 Runs multiple test cases
or suites
Implemented as subclass
of TestSuite
To create a TestSuite
 Select your testing
package
 From the context menu
select New  Other… 
Java  JUnit
 Then from the Wizard
select JUnit Test Suite
July 24, 2008
James Atlas - CISC370
23
…Creating JUnit TestSuite
• Fill in the name of
•
your TestSuite Class
Select the TestCases
to include in your
TestSuite
July 24, 2008
James Atlas - CISC370
24
TestSuite Template
package testing;
import junit.framework.Test;
public class AllTests {
public static Test suite() {
TestSuite suite =
new TestSuite("Test for testing");
//$JUnit-BEGIN$
suite.addTestSuite(FirstTestCase.class));
//$JUnit-END$
return suite;
}
}
July 24, 2008
James Atlas - CISC370
25
Running TestSuite
• Select TestSuite class
• From the Run menu
•
•
select Run  Run As 
JUnit Test
This will run the test
cases in your TestSuite
class
You will then get a
report in the JUnit
Window
July 24, 2008
James Atlas - CISC370
26
Interesting Point
• The JUnit classes TestCase and TestSuite
both implement the JUnit Test interface
• Therefore, you can add JUnit TestSuites to
other TestSuites
public static Test suite() {
TestSuite suite = new TestSuite("Test for testing");
//$JUnit-BEGIN$
suite.addTestSuite(FirstTestCase.class);
suite.addTest(OtherSuite.suite());
//$JUnit-END$
return suite;
}
}
July 24, 2008
James Atlas - CISC370
27
Bugzilla
• A “Defect Tracking System“
or "Bug-Tracking System“
• Free
• http://www.bugzilla.org/
• Used by many open-source
and community projects
(Mozilla, Apache, Linux Kernel,
Open Office, Eclipse)
and even NASA and Facebook!
July 24, 2008
James Atlas - CISC370
28
What does Bugzilla let you do?
•
•
•
•
Track bugs and code changes
Communicate with teammates
Submit and review patches
Manage quality assurance (QA)
July 24, 2008
James Atlas - CISC370
29
Bugzilla architecture
• Database (MySQL by default)
• perl code
• Web based access with email notifications
July 24, 2008
James Atlas - CISC370
30
A Bugzilla Bug (properties)
•
•
•
•
•
•
•
•
•
Product/Component - scope
Status - state in life cycle
Resolution - what happened to it
Assigned to:
Summary/Attachments/Comments
Platform/OS/Version
Priority/Severity
Reporter
Contact/CC List
July 24, 2008
James Atlas - CISC370
31
A Bugzilla
Bug
(life cycle)
July 24, 2008
James Atlas - CISC370
32
Some Bugzilla examples
• http://landfill.bugzilla.org/
 A testing site to see how Bugzilla works
• http://landfill.bugzilla.org/bugzilla-3.0branch/show_bug.cgi?id=1
 Sample bug
•
http://landfill.bugzilla.org/bugzillatip/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=rain&long_desc_type=allwordssub
str&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_white
board=&keywords_type=allwords&keywords=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&e
mailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailqa_contact2=1&em
ailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue
=&cmdtype=doit&order=Reuse+same+sort+as+last+time&field0-0-0=noop&type0-0-0=noop&value0-0-0=
 A sample query for all new or assigned bugs in
the landfill with “rain” in the short description
July 24, 2008
James Atlas - CISC370
33
Project 2
Multiplayer Card Game with Database
Client 1
Application
Server
Client 2
Database
July 24, 2008
James Atlas - CISC370
34
Project 2
Multiplayer Card Game with Database
Client 1
GUI,
networking,
3dClient
graphics,
2
sound,
AI
July 24, 2008
networking,
JDBC,
Application
J2EE,
multi-threading,
Server
JSP/Servlets
Java Databases,
Database
Fast IO
James Atlas - CISC370
35
Project 2
Multiplayer Card Game with Database
Client
Application
Server
GUI,
networking,
3d graphics,
sound,
AI
networking,
JDBC,
J2EE,
multi-threading,
JSP/Servlets
Group1
Group2
Aaron
Anshu
Brandon Joshua
James
Ray
July 24, 2008
Database
Java Databases,
Fast IO
Today:
1. Which parts will you implement?
2. Generally who will focus on what
James Atlas - CISC370
36
Project 2 General Requirements
• Users should be able to play a game locally
 You may choose to implement a new (possibly multiplayer) game or use your Freecell game from Project 1
 They will need to log in to the game server
• Game Server
 Keeps track of user names/passwords, game history
(wins/losses)
 Provides web access to a user account and displays
user’s game history
 Must keep track of this in a database
July 24, 2008
James Atlas - CISC370
37