Software Testing - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Software Testing

Description:

... and a suite, use Eclipse and create a JAR when done ... Contract: Post, pre-conditions, invariants and assertions (every class: ... Test cases are ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 13
Provided by: usersC1
Category:
Tags: ajar | software | testing

less

Transcript and Presenter's Notes

Title: Software Testing


1
Software Testing
  • Section 6.4 (JIAs)
  • Chapter 13 (ALBINGs)

2
Announcements
  • Assignment due Monday
  • Test Blender Given code, check that it works
    properly, devise two test classes, and a suite,
    use Eclipse and create a JAR when done
  • Phase 6 due Nov. 30th
  • Update to reflect most recent design
  • Packages
  • Contract Post, pre-conditions, invariants and
    assertions (every class wellFormed() method)
  • Tests
  • One for every class
  • Test suite to call all

3
JUnit Test Framework
Test
TestResult
run(TestResult)
TestCase
TestSuite
testNameString
run(TestResult)
run(TestResult)
addTest()
setUp()
tearDown()
YOURTestCase
setUp()
tearDown()
4
JUnit and Eclipse
  • Test cases are ordinary Java classes
  • Should collect the test classes in a separate
    source folder dedicated to unit tests
  • One test class for every class in application
  • This separation enables you to easily omit tests
    from production code distribution
  • Easier for team to manage

5
JUnit and Eclipse
  • Typically, we create another folder in the
    project called test
  • In addition to bin for classes and src for code
  • Mimic the same package hierarchy/directory
    structure of src in test
  • Why?
  • Allows your units test cases to access protected
    and package-protected methods in the class being
    tested
  • CAVEAT Since package names are the same, test
    case classes must have names different from class
    being tested
  • Append Test to the end of the class being tested
  • AccountTest tests Account

6
Writing Test Classes in Eclipse
  • In Java Perspective
  • Right click on the project to be test, and create
    a new tests folder
  • (done once for all test case classes of a
    project)
  • New gt SourceFolder
  • Right click the class to be tested
  • Select New gt JUnit Test Case
  • In wizard
  • Source Folder must point to test folder
  • Package
  • Name
  • Superclass (junit.framework.TestCase)
  • Check the setUp() method
  • Class under test
  • Click Next
  • Select to methods to be tested from this class
  • Fill in the test methods as needed

7
(No Transcript)
8
Running a Test Case
  • In Java Perspective
  • Right click the test case
  • Select Run As gt JUnit Test
  • To run a single method from a test case
  • Useful when debugging the test method themselves
  • Right the desired method in the Outline view
    (while editing the test case class)
  • Select Run As gt JUnit Test
  • To run all test cases inside a package, a source
    folder, or project
  • Right the desired package, source folder, project
    in the Package Explorer
  • Select Run As gt JUnit Test

9
JUnit View
  • Notice the green/red status bar
  • Expand the tested entity to view each test method
  • Failed methods have stacks of messages in the
    Failure Trace portion of the JUnit View
  • Click any stack frame message to view
    corresponding code
  • When assertions compare two Strings, an
    additional comparison viewer is available
  • See next slide

10
JUnit View
  • Filter Stack Trace
  • remove stack trace entries related to JUnit
    infrastructure
  • Compare Results
  • available when assertEquals() fails
  • When used to compare two string value

11
Creating a Test Suite
  • A Test Suite is a group of related JUnit tests
  • FilegtNewgtOthergtJavagtJUnitgtJUnit Test Suitegt Next
  • Select the test case classes to include

12
Group Exercise
  • Migrate Project to Eclipse
  • Divide classes into meaningful packages
  • Package for Core classes used everywhere
  • By Services (i.e. Transactions, Bill and Inquiry)
  • Update code accordingly (imports and package
    definitions)
  • Create a new project in Eclipse and import code
  • Make sure you have a bin folder for class files
    (better yet, a src folder for source code files)
  • Ensure that code on Eclipse reflects your package
    design
Write a Comment
User Comments (0)
About PowerShow.com