Top Banner
JUnit, Bugzilla JUnit, Bugzilla James Atlas James Atlas July 24, 2008 July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL under the EPL
37

JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

Jan 18, 2018

Download

Documents

Elvin Farmer

July 24, 2008James Atlas - CISC3703 Today Software testing Software testing  JUnit  Mantis An important part of all software develoment processes An important part of all software develoment processes
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

JUnit, BugzillaJUnit, Bugzilla

James AtlasJames AtlasJuly 24, 2008July 24, 2008

*part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL

Page 2: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 22

ReviewReview• Reflection APIReflection API• JDBC/HibernateJDBC/Hibernate• Distributed Programming/RMIDistributed Programming/RMI

Page 3: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 33

TodayToday• Software testingSoftware testing

JUnitJUnit MantisMantis

• An important part of all software develoment An important part of all software develoment processesprocesses

Page 4: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 44

Software Development Software Development ProcessesProcesses• ModelsModels

Waterfall (sequential steps)Waterfall (sequential steps)1.1. Requirements specification (AKA Verification)Requirements specification (AKA Verification)2.2. DesignDesign3.3. Construction (AKA implementation or coding)Construction (AKA implementation or coding)4.4. IntegrationIntegration5.5. Testing and debugging (AKA validation)Testing and debugging (AKA validation)6.6. Installation (AKA deployment)Installation (AKA deployment)7.7. MaintenanceMaintenance

Page 5: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 55

Software Development Software Development ProcessesProcesses• Models (cont’)Models (cont’)

Agile (iterative steps)Agile (iterative steps)1.1. Develop testsDevelop tests2.2. Implementation/codingImplementation/coding3.3. Design/refactoringDesign/refactoring• Direct feedback/communication between Direct feedback/communication between

customer and software developercustomer and software developer

Page 6: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 66

Software TestingSoftware Testing• Simple/naïve methodsSimple/naïve methods

debuggerdebugger printed outputprinted output

• How should we go about testing our code?How should we go about testing our code?

Page 7: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 77

Software TestingSoftware Testing• Simple/naïve methodsSimple/naïve methods

debuggerdebugger printed outputprinted output

• How should we go about testing our code?How should we go about testing our code? automation!automation!

Page 8: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 88

Software TestingSoftware Testing• UnitUnit

per module testingper module testing ensures components interact appropriatelyensures components interact appropriately

• SystemSystem system works in realistic environmentsystem works in realistic environment

• User AcceptanceUser Acceptance system supports the business for which it was system supports the business for which it was

designeddesigned

Page 9: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 99

JUnitJUnit• What is JUnit?What is JUnit?• Where Does it Come From?Where Does it Come From?• Working with TestCasesWorking with TestCases• Working with TestSuitesWorking with TestSuites• JUnit WindowJUnit Window

Page 10: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1010

What is JUnit?What is JUnit?• Regression testing frameworkRegression testing framework• Written by Erich Gamma and Kent BeckWritten by Erich Gamma and Kent Beck• Used for unit testing in JavaUsed for unit testing in Java• Open SourceOpen Source• Released under IBM's CPLReleased under IBM's CPL

Page 11: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1111

Where Does JUnit Come From?Where Does JUnit Come From?• JUnit’s web site: JUnit’s web site:

http://junit.org/index.htmhttp://junit.org/index.htm• Eclipse includes JUnitEclipse includes JUnit

Eclipse provides new GUI to run JUnit test cases Eclipse provides new GUI to run JUnit test cases and suitesand suites

• You can run your unit tests outside of EclipseYou can run your unit tests outside of Eclipse If you wish using If you wish using TestRunnerTestRunner Using JUnit’s WindowUsing JUnit’s Window

Page 12: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1212

Eclipse JUnit SetupEclipse JUnit Setup• Eclipse preferences Eclipse preferences

can be set in the JUnit can be set in the JUnit Preferences windowPreferences window

• For the most part you For the most part you can leave these alonecan leave these alone

• Filters needed to Filters needed to identify packages, identify packages, classes, or patterns classes, or patterns that should not be that should not be shown in the stack shown in the stack trace of a test failure trace of a test failure

Page 13: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1313

JUnit Test CasesJUnit Test Cases• Test case Test case

Runs multiple testsRuns multiple tests

• Implemented a subclass of Implemented a subclass of TestCaseTestCase• Define instance variables that store the state Define instance variables that store the state

of the tests in the classof the tests in the class• Initialize Initialize TestCaseTestCase by overriding by overriding setUpsetUp

methodmethod• Clean-up after test case is done by Clean-up after test case is done by

overriding overriding tearDowntearDown method method

Page 14: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1414

Creating Creating TestCasesTestCases in Eclipse… in Eclipse…• Create a new package to contain your test case classesCreate a new package to contain your test case classes• Add the JUnit JAR file to the project’s buildpathAdd the JUnit JAR file to the project’s buildpath• Or, will be done for you the first time you build a test Or, will be done for you the first time you build a test

casecase

Page 15: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1515

……Creating Creating TestCasesTestCases in Eclipse in Eclipse• Select your testing Select your testing

packagepackage• From the context menu From the context menu

select select New New JUnit JUnit Test CaseTest Case

• In the next Window fill In the next Window fill in the name of your test in the name of your test casecase

• This will create the This will create the corresponding class in corresponding class in your testing packageyour testing package

Page 16: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1616

TestCaseTestCase Template Templatepackage 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();

}}

Page 17: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1717

Adding Tests to Adding Tests to TestCasesTestCases• Any method in a Any method in a TestCaseTestCase class is class is

considered a test if it begins with the word considered a test if it begins with the word testtest You can write many tests (have many test You can write many tests (have many test

methods)methods)

• Each test method should use a variety of Each test method should use a variety of assert methods to test things about the state assert methods to test things about the state of their classes under testsof their classes under tests Assert methods are inheritedAssert methods are inherited

Page 18: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1818

Assert MethodsAssert Methods• Assert methods include:Assert methods include:

assertEqual(x,y)assertEqual(x,y) assertFalse(boolean)assertFalse(boolean) assertTrue(boolean)assertTrue(boolean) assertNull(object)assertNull(object) assertNotNull(object)assertNotNull(object) assertSame(firstObject, secondObject)assertSame(firstObject, secondObject) assertNotSame(firstObject, secondObject)assertNotSame(firstObject, secondObject)

Page 19: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 1919

Adding Two Tests to TestCaseAdding Two Tests to TestCasepackage 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}

}

Page 20: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2020

Running Running TestCaseTestCase• Select Select TestCaseTestCase class class• From the Run menu From the Run menu

select select Run Run Run As Run As JUnit TestJUnit Test

• This will run the tests in This will run the tests in your your TestCaseTestCase class class along with the setup along with the setup and teardown methodsand teardown methods

• You will then get a You will then get a report in the JUnit report in the JUnit WindowWindow

Page 21: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2121

JUnit Window…JUnit Window…• Red indicates a Red indicates a

test has failedtest has failed• If you wish to If you wish to

see the tests in see the tests in TestCaseTestCase click click on the Hierarchy on the Hierarchy tabtab

• You can see You can see which test failedwhich test failed

• You can see the You can see the call trace leading call trace leading to the failureto the failure

Page 22: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2222

• You can see how many You can see how many tests rantests ran

• Errors occur when Errors occur when exceptions are thrownexceptions are thrown

• How many failures How many failures occurredoccurred

• You can see the details You can see the details of the failureof the failure

……JUnit WindowJUnit Window

Page 23: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2323

Creating JUnit Creating JUnit TestSuiteTestSuite……• Test Suite Test Suite

Runs multiple test cases Runs multiple test cases or suitesor suites

• Implemented as subclass Implemented as subclass of of TestSuiteTestSuite

• To create a To create a TestSuiteTestSuite Select your testing Select your testing

packagepackage From the context menu From the context menu

select select New New Other… Other… Java Java JUnitJUnit

Then from the Wizard Then from the Wizard select select JUnit Test SuiteJUnit Test Suite

Page 24: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2424

……Creating JUnit Creating JUnit TestSuiteTestSuite• Fill in the name of Fill in the name of

your your TestSuiteTestSuite ClassClass

• Select the Select the TestCasesTestCases to to include in your include in your TestSuiteTestSuite

Page 25: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2525

TestSuiteTestSuite Template Templatepackage 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;

}}

Page 26: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2626

Running Running TestSuiteTestSuite• Select Select TestSuiteTestSuite class class• From the Run menu From the Run menu

select select Run Run Run As Run As

JUnit TestJUnit Test• This will run the test This will run the test

cases in your cases in your TestSuiteTestSuite class class

• You will then get a You will then get a report in the JUnit report in the JUnit WindowWindow

Page 27: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2727

Interesting PointInteresting Point• The JUnit classes The JUnit classes TestCaseTestCase and and TestSuiteTestSuite

both implement the JUnit both implement the JUnit TestTest interface interface• Therefore, you can add JUnit Therefore, you can add JUnit TestSuitesTestSuites to to

other other TestSuitesTestSuitespublic static Test suite() {

TestSuite suite = new TestSuite("Test for testing");//$JUnit-BEGIN$suite.addTestSuite(FirstTestCase.class);

suite.addTest(OtherSuite.suite());//$JUnit-END$return suite;

}}

Page 28: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2828

BugzillaBugzilla• A “Defect Tracking System“A “Defect Tracking System“

or "Bug-Tracking System“ or "Bug-Tracking System“• FreeFree• http://www.bugzilla.org/http://www.bugzilla.org/• Used by many open-sourceUsed by many open-source

and community projectsand community projects(Mozilla, Apache, Linux Kernel,(Mozilla, Apache, Linux Kernel,Open Office, Eclipse)Open Office, Eclipse)and even NASA and Facebook!and even NASA and Facebook!

Page 29: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 2929

What does Bugzilla let you do?What does Bugzilla let you do?• Track bugs and code changesTrack bugs and code changes• Communicate with teammatesCommunicate with teammates• Submit and review patchesSubmit and review patches• Manage quality assurance (QA)Manage quality assurance (QA)

Page 30: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3030

Bugzilla architectureBugzilla architecture• Database (MySQL by default)Database (MySQL by default)• perl codeperl code• Web based access with email notificationsWeb based access with email notifications

Page 31: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3131

A Bugzilla Bug (properties)A Bugzilla Bug (properties)• Product/Component - scopeProduct/Component - scope• Status - state in life cycleStatus - state in life cycle• Resolution - what happened to itResolution - what happened to it• Assigned to:Assigned to:• Summary/Attachments/CommentsSummary/Attachments/Comments• Platform/OS/VersionPlatform/OS/Version• Priority/SeverityPriority/Severity• ReporterReporter• Contact/CC ListContact/CC List

Page 32: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3232

A Bugzilla A Bugzilla Bug Bug (life cycle)(life cycle)

Page 33: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3333

Some Bugzilla examplesSome Bugzilla examples• http://landfill.bugzilla.org/http://landfill.bugzilla.org/

A testing site to see how Bugzilla worksA testing site to see how Bugzilla works

• http://landfill.bugzilla.org/bugzilla-3.0-http://landfill.bugzilla.org/bugzilla-3.0-branch/show_bug.cgi?id=1branch/show_bug.cgi?id=1 Sample bugSample bug

• http://landfill.bugzilla.org/bugzilla-tip/buglist.cgi?http://landfill.bugzilla.org/bugzilla-tip/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=rain&long_desc_type=allwordssubstr&long_desquery_format=advanced&short_desc_type=allwordssubstr&short_desc=rain&long_desc_type=allwordssubstr&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keyc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassignewords_type=allwords&keywords=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailqa_contact2=1&emailcc2=1&ed_to1=1&emailtype1=substring&email1=&emailassigned_to2=1&emailreporter2=1&emailqa_contact2=1&emailcc2=1&emailtype2=substring&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtypmailtype2=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=e=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 A sample query for all new or assigned bugs in the landfill with “rain” in the short descriptionthe landfill with “rain” in the short description

Page 34: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3434

Project 2Project 2

ApplicationServer

Client 1

Multiplayer Card Game with Database

Client 2

Database

Page 35: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3535

Project 2Project 2

ApplicationServer

Client 1

Multiplayer Card Game with Database

Client 2

Database

GUI,networking,3d graphics,

sound,AI

networking,JDBC,J2EE,

multi-threading,JSP/Servlets

Java Databases,Fast IO

Page 36: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3636

Project 2Project 2

ApplicationServer

Client

Multiplayer Card Game with Database

Database

GUI,networking,3d graphics,

sound,AI

networking,JDBC,J2EE,

multi-threading,JSP/Servlets

Java Databases,Fast IO

Group1

AaronBrandonJames

Group2

AnshuJoshuaRay

Today:1. Which parts will you implement?2. Generally who will focus on what

Page 37: JUnit, Bugzilla James Atlas July 24, 2008 *part of today’s slides courtesy of Dwight Deugo and Nesa Matic under the EPL.

July 24, 2008July 24, 2008 James Atlas - CISC370James Atlas - CISC370 3737

Project 2 General RequirementsProject 2 General Requirements• Users should be able to play a game locallyUsers should be able to play a game locally

You may choose to implement a new (possibly multi-You may choose to implement a new (possibly multi-player) game or use your Freecell game from Project 1player) game or use your Freecell game from Project 1

They will need to log in to the game serverThey will need to log in to the game server

• Game ServerGame Server Keeps track of user names/passwords, game history Keeps track of user names/passwords, game history

(wins/losses)(wins/losses) Provides web access to a user account and displays Provides web access to a user account and displays

user’s game historyuser’s game history Must keep track of this in a databaseMust keep track of this in a database