SE-2832 Introduction to Software Verification

Dr. Mark Sebern -- Spring quarter 2013-2014


Lab 6

Revised: 16 April 2014

Acknowledgment

This lab was developed by Dr. Walt Schilling; all errors in its adaptation are the responsibility of the instructor.

Overview

In this lab, you will work in a small team (2-3 members) to implement tests using the jMock mock object framework. You may not do this lab by yourself.

Background information

You may wish to consult some of the following materials regarding jMock:

Lab Assignment

In this lab, you will use the jMock toolset to create mock objects and, in conjunction with the TestNG test framework, to test the behavior of a stock ticker system.

The MSOE stock ticker is designed to monitor the stock market and determine the fate of the vast numbers of investments in your personal portfolio. You can download the source code from:

When the system is started, the user enters:

When operating, the system will query the remote server every n seconds (where n is the refresh interval) and generate a ticker report that is then written to the console.

A sample of the program's output looks like this:

###################################################################################
Ford Motor Co.(F):               $1.99       (0%)   $1.99    ---  (-4.33%)  $2.08
Cedar Fair(FUN):                $13.89       (0%)   $13.89   --   (-1.91%)  $14.16
General Motors Corp(GM):         $4.89       (0%)   $4.89    +++  (2.73%)   $4.76
Verizon Communications(VZ):     $26.77       (0%)   $26.77   +++  (3.24%)   $25.93
AT&T Corp(T):                   $22.42       (0%)   $22.42   ---  (-2.52%)  $23.00
Genl Electric(GE):              $21.50       (0%)   $21.50   +++++(13.1%)   $19.01
Six Flags(SIX):                  $0.40       (0%)   $0.40    -----(-11.11%) $0.45
Walgreen Company(WAG):          $23.22       (0%)   $23.22   ---- (-8.15%)  $25.28
Agilent Technologies Inc.(A):   $22.48       (0%)   $22.48   --   (-1.23%)  $22.76
Microsoft Corp(MSFT):           $21.50       (0%)   $21.50   ---  (-3.59%)  $22.30
Intl Bus. Machines(IBM):        $87.75       (0%)   $87.75   --   (-1.4%)   $89.00
Morgan J.P. & Co. Inc.(JPM):    $41.64       (0%)   $41.64   +++++(13.52%)  $36.68
Wells Fargo & Company(WFC):     $28.31       (0%)   $28.31   +++  (3.89%)   $27.25
Bank of America(BAC):           $20.87       (0%)   $20.87   ++++ (6.32%)   $19.63
Citigroup Inc.(C):              $14.11       (0%)   $14.11   ++++ (9.13%)   $12.93
###################################################################################

The first segment lists the name of the company and the stock symbol. That is followed by the value of the stock on the previous check (n seconds ago, where n is the refresh interval). The change since the last check is then shown, with a series of + or – signs designating if the stock has gone up or down and a percentage of the change. The number of +/- signs is:

This is followed by the printing of the current price of the stock. The current price is followed by the same data printed relative to the open of the stock today. If the change since the last time is greater than 1⁄2% or the change since yesterday is greater than 3%, then either happy (“We’re in the Money”) or sad music (“GRRR”) will be played, depending on whether the market is up or down.

If an error occurs, and the system is unable to connect with the web site to download a quote, an error message will be printed and an error message (“Failure is not an option”) will be played.

Your job is to:

  1. Test the application to determine whether it is working correctly.
  2. Record any defects that you find.
  3. Fix the defects, if any, and re-run the tests.
  4. Report on your work.

Once you have installed jMock, take a look at the tutorial on developing mock objects with jMock. You will need to record the expected behavior as part of a scenario inside of a mock object. Once the behavior is recorded, you can switch the mock object into a playback mode and make calls into the source code to invoke the sequences.

When that step is complete, you then verify whether the resulting behavior matches the expected scenario. The main area you should test is the StockQuoteAnalyzer class. Testing this class using jMock requires you to mock the behavior for the StockQuoteGeneratorInterface interface and the StockTickerAudioInterface class.

Assignment submission (due by 11:59PM CDT, Tuesday, April 22)

Prepare a PDF report (named "SE2832-username1-username2-username3-Lab6.pdf" (using dashes, not underscores, with the specified capitalization), where each "usernameN" is the lowercase MSOE email username of a team member) on your lab experience, including:

If you have any questions, consult the instructor.