Adam's Lair Forum

Unit Testing
Page 1 of 1

Author:  Adam [ 2014/01/27, 20:17 ]
Post subject:  Unit Testing

Blog entry:
Unit Testing
So you might have heard of this development trick called Unit Testing – most likely in the context of some business application or software engineering talk, but probably not related to games. It’s something that large, bulky projects have, with a ton of different programmers working on the same stuff, but it doesn’t make sense to do something like this yourself, right?

[ Read more ]

Author:  BraveSirAndrew [ 2014/01/30, 16:37 ]
Post subject:  Re: Unit Testing

Hey Adam

It's great to see that you're embracing testing. Duality is an amazingly stable piece of code for it's size, but as it grows and hopefully becomes more of a community driven effort, tests will make a huge difference in the quality.

I just wanted to bring up one of your guidelines for when to write tests. You said

When writing a new game component or engine feature you’re still experimenting with: Don’t Unit-Test that.

I just wanted to mention Test Driven Development and see if that's something you're familiar with. TDD actually helps to improve the design of your APIs because the tests become basically like any other client of your code, and help to show you where your code is too coupled by being difficult to write. In TDD, you write a small test first, then write the code to make the test pass. If you're looking for a good example of TDD tests, check out scriptcs. They're very nicely written in that (and also it's a project we're investigating to add scripting support to Duality. Early tests are promising:) ).

That said, I'm all for hacking some code together to explore an idea first, so long as that code is thrown away and re-written with tests.

Author:  Adam [ 2014/01/30, 17:04 ]
Post subject:  Re: Unit Testing

Hey Andrew,

yeah well, I was almost expecting someone to bring up TDD when I wrote that one guideline. :D It's probably worded poorly. I have applied the TDD kind of workflow once, when I wrote Duality's RawList<T> class. It worked remarkably well and I would definitely do it again! Thumbs up for TDD in general, that is.

My point is just, that I can't seem to apply TDD very often. Something like a custom dynamic array wrapper has an obvious design and straightforward use cases, is easy to test and I pretty much know how the class design will look like before I even begin to start writing code. But in 90% of the time, this is not how it works for me. Instead, I sketch a systems design roughly in my head, and start programming shortly after, altering overall structure, API and functionality frequently. It is not practical for me to write tests at this stage, because it will all change anyway before I've even done my first commit - and not because I'm really bad at designing stuff, but simply because, to me, programming and design is a very dynamic, fluid process.

So, you can of course unit-test new things directly, and write tests up-front or while you're at it. I guess what I'm trying to say in this personal guideline is just: Don't do it until you have an idea of what you're dealing with.

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group