Game Development Community

dev|Pro Game Development Curriculum

ScriptT3D: Testing in Progress ... errr ... DONE!

by Demolishun · 12/02/2012 (12:06 pm) · 7 comments

Update:
We interrupt the old blog content to bring you breaking news.

MIT Version of ScriptT3D Released!!!

ScriptT3D Resource
Yeah, I am done with the rewrite. The code is cleaned up, tested, and ready for more eyes. I think this is definitely the most solid release of ScriptT3D to date. Try it out, give me comments so I can cry into some tissues, and then I will fix the bugs or explain the "features".

Previous Blog Content:
Seriously, I must be a glutton for brain damage. I am in the process of learning to test the ScriptT3D interface to T3D. So I have delved into Unit Testing. The strange thing is that I kind of think it is fun. Part of the fun is the frame work was written by someone else. Python comes with a Unit Testing module called unittest. So it makes it a nobrainer to setup test fixtures and execute them. It is also something I have never done before so that makes it slightly more exciting than brushing your teeth.

The main driver for using unit testing is to reduce time spent finding out if changes I make introduced a bug. The interface I have created is somewhat complex. It would be easy to make a small change that is not noticeable readily. Another reason is I really should know how to unit test my code. As a professional coder I am often building interfaces for things and often waste time tracking down simple issues. Having some more tools to find issues with my code is a good thing. So I am getting pretty far along in testing my interface. I have a testing fixture setup so I can just add tests as determine parts that need testing. This all means that the code will be much more robust and maintainable in the future.

Here is a quick example of the unit test code:
# define unit tests
class SimObjectTests(unittest.TestCase):
    # setup for each test
    def setUp(self):
        # create a new SimObject for each test
        self.simobject = engine.evaluate('return new SimObject(TestSimObject);')
    # cleanup for each test
    def tearDown(self):
        # delete SimObject after each test
        engine.evaluate('{0}.delete();'.format(self.simobject))

    # tests
    def test_SimObjectsAccessByID(self):
        obj = SimObjects[self.simobject]
        objId = obj.getId()
        self.assertEqual(self.simobject, objId)
        #self.assertTrue(self.simobject == objId)

    def test_SimObjectsAccessByName(self):
        obj = SimObjects.TestSimObject
        objId = obj.getId()
        self.assertEqual(self.simobject, objId)
        #self.assertTrue(self.simobject == objId)

    def test_SimObjectsAttribException(self):
        with self.assertRaises(AttributeError):
            obj = SimObjects.badObject

    def test_SimObjectsKeyException(self):
        with self.assertRaises(KeyError):
            obj = SimObjects["badObject"]
        obj = SimObjects.TestSimObject
        objId = obj.getId()
        with self.assertRaises(KeyError):
            obj = SimObjects[int(objId)+100]
Here is the result of running this suite of tests:
Starting Unit Tests
test_SimObjectsAccessByID (__main__.SimObjectTests) ... ok
test_SimObjectsAccessByName (__main__.SimObjectTests) ... ok
test_SimObjectsAttribException (__main__.SimObjectTests) ... ok
test_SimObjectsKeyException (__main__.SimObjectTests) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.021s

OK
Finished Unit Tests

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
12/02/2012 (2:32 pm)
Lots of times unit testing is just vexing but I can see how it helps you out for code of this complexity.
#2
12/02/2012 (3:23 pm)
Yes, you have to get creative sometimes. Testing this code helped me find a lot of minor bugs. So I am glad I did it.
#3
12/02/2012 (9:20 pm)
Time to turn that the other way around and try out test-driven development. Write the tests and then code to pass them.
#4
12/03/2012 (7:34 am)
Well, I am working on these:
assertEqual(Player.likes,Game.play)
assertEqual(Player.paid,Game.price)
#5
12/11/2012 (1:03 pm)
@Frank : Two Gold lines... lol
#6
12/22/2012 (12:56 am)
@Vincent: Thanks!
#7
08/03/2013 (9:20 am)
@Demolishun the more I read about the ScriptT3D for the article I'm writing, the more psyched I get about it. How come no one has been digging more into this resource? It's pure gold!

There is the beginning for all the script languages people are requesting! Java, C#, Lua. People just don't like the idea of having to make a little work themselves and having to write the language support for these lol.

This is really a gem, and should be the starting point for any new scripting languages added to T3D. Great job!