Unit Testing

Recently I have taken to unit testing my code before I write it,this doesn’t exactly speed up the development process, but it does mean the code compiles for a much greater amount of time.

One little issue I have come across is whether or not I should be testing internal classes.  I can test the public interface on a public class with no issues, but if I have an internal component with which a public class is to interact, I feel compelled to test the interface of that class to make sure it does what it should be doing.

I have found a number of solutions to this problem, none of which I am terribly happy with

  1. Use conditional expressions to either
    1. Add a test to the assembly – too messy
    2. change the scope of a variable so it can be tested – I should not be testing members directly
  2. Link an internal class into the testing assembly, I haven’t yet tried this – Is this a good habit to get into.

Writing tests before I write code gives me a much better view of the problem because I must think of it “externally” before I bother with it’s implementation, I am forced to think up a test that boils the whole problem down to an assertion, when that assertion stops being false, my job is done.

Advertisements

One thought on “Unit Testing

  1. ok just reading through the catch up and now i am upset – apple is ok. well you know that i would take that stand 😉

    i got me new puter – the macbook intel chip

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s