Skip to content

4. JUnit Tests

Tomás edited this page Jun 21, 2020 · 1 revision

Introduction to our Test Units.

Every JUnit Test we created and used during the project's development can be found in the "...\src\tests" directory. Every JUnit Test class will be detailed here so as to get a feeling of their use and code.

TestCommons

This is the backbone of our tests. To some degree almost every element on the project depends on an existing market or game and some bot existing to be doing stuff. For this purpose we created this class. It has two methods of its own:

  • initGameAndMarket(): This establishes context and a game for the other methods to call.
  • botDummy(): Returns a bot dummy to test everything that needs a player (class from which bot inherits).

It extends TestCase so every other test classes we made can inherit from this so as to have the methods and also the assertions.

ActionTest

This test class allows to test a generic action and the functionality of the moveActions on a bot dummy using two methods:

  • performAction(): Checks that a bot can perform an action and that the action consequences will be reflected on the bot.
  • performMoveAction(): Checks that a bot can perform a MoveAction, and that the MoveAction will move him from one location to another.

AssetTest

This test class tests assets with two methods:

  • refreshAsset(): Checks for asset state and price change when refreshing assets.
  • assetNameGen(): Checks assets have a generated name.

BankerTest

This test class tests the Banker class with three methods:

  • giveLoan(): Checks banker can give loans.
  • savingLoan(): Checks banker can give a loan for a bankrupt person and that it will be more abusive.
  • loan12000Limit(): Checks that the amount given by a banker can never excede $12000.

ChooseActionStrategyTest

This test class tests the ChooseActionStrategy class with two methods:

  • LocWithFoodTest(): Checks SeekFoodStrategy will seek for a food related action to execute.
  • LocWithMentalTest(): Checks SeekMentalHealthStrategy will seek for a food related action to execute.

LifeTest

This test class tests the MentalHealth and Hunger classes with two methods:

  • statsTest(): Checks addition and subtraction of stats works and that their limit is 100.
  • statsStringTest(): Checks hunger and health have toString() methods.

MarketInteractionsTest

This test class tests the market and its interactions and Hunger classes with two methods:

  • buy(): Checks a bot dummy can buy assets.
  • sell(): Checks a bot dummy can sell assets.

MarketTest

This test class tests the market with five methods:

  • marketSingletonCreationTest(): Checks market will be created through getInstance().
  • canBuyAny(): Checks canBuyAnyWith(int Money) method works and returns true if you can buy some asset with some amount of money.
  • minStart1(): Checks minimumAsstets and startingAssets work and don't cause problems.
  • minStart2(): Checks minimumAsstets and startingAssets work and don't cause problems.
  • noNegativeAsset(): Checks that every asset's price is always positive.

TimeTestCase

This test class tests the Time class with one method:

  • timeTest(): Checks times can be created, times can have minutes added to them, some time can be checked to be before another one and that their toString() methods explain the time correctly.