O'Reilly logo

Sage Beginner's Guide by Craig Finch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - creating unit tests for the Tank class

Let's see how unittest can help us test the Tank class. Enter the following code into a text file in the same directory as the combatsim package:

 import combatsim import combatsim.exceptions as ex import unittest class TestTank(unittest.TestCase): """Tests for the combatsim package.""" def setUp(self): """Called before EACH test is run.""" # Define parameters for the tank armor_values = {'front' : 100, 'side' : 50, 'rear' : 25, 'turret' : 75} main_gun_damage = 50 initial_position = (0.0, 0.0) # Create a tank object self.tank = combatsim.tank.Tank(armor_values, main_gun_damage, initial_position) def test_get_position(self): """Test method get_position""" position = self.tank.get_position() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required