Skip to topic | Skip to bottom
Minfo.SeTD2y1314r1.2 - 13 Oct 2013 - 21:44 - PhilippeCollettopic end

Start of topic | Skip to actions

Lab 2 : Unit testing


Return of the Creature

Download and create a new project for this lab. It contains :

  • a correction for the SmartCreature
  • some small changes with some methods moved at appropriate places
  • the code for a BouncingCreature :
    • it randomly changes direction (see the "noise" part)
    • it is supposed to bounce on the wall
But it is buggy... Run the launcher and see.

Exercise 1: first test on the random creature

  • Think on how to organize tests (what is the surrounding setup, what are you going to test, how, which values, etc.)
  • Create a first test (use the wizard and use help on fixing the project setup to include junit library)

Exercise 2: the 3 errors game

There are 3 errors in the BouncingCreature. Find them with the right tests and correct the code.

Exercise 3: mock objects

Set up:

  1. Download mockito library mockito-all-1.9.5.jar
  2. Create a new directory in your project called lib
  3. Copy there the downloaded mockito jar file
  4. Right click the jar file and select Build Path -> Add to build path

Change the previous tests so to mock the environment: think of the methods that are used by the creature...

Exercise 4: testing the smartness...

  • Create a single test (with mock as well) to verify the basic algorithm of the SmartCreature.
  • Add to this test some "verify" statement of mockito to check the interactions between the creature and its environment.

-- PhilippeCollet - 13 Oct 2013

to top

You are here: Minfo > SeTD2y1314

to top

Copyright © 1999-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WIKIDeptinfo? Send feedback