Skip to main content

The guys at JUnit (Java Unit test framework) have a philosophy that if it is too simple to test, don't test it. I highly recommend reading their Best Practices FAQBest Practices FAQ, as it is fairly pragmatic.

TDD is a different process of writing your software. The basic premise behind unit testing is that you will spend less time in the debugger stepping through code, and more quickly figure out if your code change accidentally breaks something else in the system. That fits in with TDD. The TDD cycle is like this:

  1. Write a test
  2. Watch it fail (prove you have something to do)
  3. Write just what is needed to make the test pass--no more.
  4. Watch it pass (yay!)
  5. Refactor (make it better)
  6. Wash, rinse, and repeat

What is less obvious about applying TDD is that it changes the way your write code. By forcing yourself to think about how to test/validate that the code is working, you are writing testable code. And since we are talking unit testing, that usually means that your code becomes more modular. To me, modular and testable code is a big win up front.

Now, do you need to test things like C# properties? Imagine a property defined like this:

bool IsWorthTesting {get; set;}

The answer would be "no" it's not worth testing, because at this point you are testing the language feature. Just trust that the C# platform guys got it right. Besides, if it failed, what could you do to fix it?

Also, you will find that there are certain parts of your code that very well will be too much effort to test properly. That means don't do it, but make sure you test the code that uses/is used by the tricky problem:

  • Checked exceptions that can only occur if an install went bad. Java has a ton of these. You are required to write a catch block or declare the checked exception even if there is no way it can fail without hacking the installed files.
  • User interfaces. Finding the control under test, and invoking the right events to simulate a user's actions are very troublesome, and in some cases impossible. However, if you use the Model/View/Controller pattern, you can make sure your model and controllers are tested and leave the view part to manual testing.
  • Client/server interactions. This is no longer a unit test, and is now an integration test. Write all the parts that go up to sending and receiving messages over the wire, but don't actually go over the wire. A good approach is to reduce the responsibility of the code that actually talks over the wire to the raw communications. In your unit test code, mock communication object out to make sure the services are behaving as you expect.

Believe it or not, TDD will help you fall into a sustainable pace of development. It's not because of magic, but rather because you have a tight feedback loop and you are able to catch really dumb mistakes quickly. The cost of fixing those mistakes is essentially constant (at least enough for planning purposes) because the small mistakes never grow up to be big mistakes. Compare that with the bursty nature of code binge/debug purge sprints.

The guys at JUnit (Java Unit test framework) have a philosophy that if it is too simple to test, don't test it. I highly recommend reading their Best Practices FAQ, as it is fairly pragmatic.

TDD is a different process of writing your software. The basic premise behind unit testing is that you will spend less time in the debugger stepping through code, and more quickly figure out if your code change accidentally breaks something else in the system. That fits in with TDD. The TDD cycle is like this:

  1. Write a test
  2. Watch it fail (prove you have something to do)
  3. Write just what is needed to make the test pass--no more.
  4. Watch it pass (yay!)
  5. Refactor (make it better)
  6. Wash, rinse, and repeat

What is less obvious about applying TDD is that it changes the way your write code. By forcing yourself to think about how to test/validate that the code is working, you are writing testable code. And since we are talking unit testing, that usually means that your code becomes more modular. To me, modular and testable code is a big win up front.

Now, do you need to test things like C# properties? Imagine a property defined like this:

bool IsWorthTesting {get; set;}

The answer would be "no" it's not worth testing, because at this point you are testing the language feature. Just trust that the C# platform guys got it right. Besides, if it failed, what could you do to fix it?

Also, you will find that there are certain parts of your code that very well will be too much effort to test properly. That means don't do it, but make sure you test the code that uses/is used by the tricky problem:

  • Checked exceptions that can only occur if an install went bad. Java has a ton of these. You are required to write a catch block or declare the checked exception even if there is no way it can fail without hacking the installed files.
  • User interfaces. Finding the control under test, and invoking the right events to simulate a user's actions are very troublesome, and in some cases impossible. However, if you use the Model/View/Controller pattern, you can make sure your model and controllers are tested and leave the view part to manual testing.
  • Client/server interactions. This is no longer a unit test, and is now an integration test. Write all the parts that go up to sending and receiving messages over the wire, but don't actually go over the wire. A good approach is to reduce the responsibility of the code that actually talks over the wire to the raw communications. In your unit test code, mock communication object out to make sure the services are behaving as you expect.

Believe it or not, TDD will help you fall into a sustainable pace of development. It's not because of magic, but rather because you have a tight feedback loop and you are able to catch really dumb mistakes quickly. The cost of fixing those mistakes is essentially constant (at least enough for planning purposes) because the small mistakes never grow up to be big mistakes. Compare that with the bursty nature of code binge/debug purge sprints.

The guys at JUnit (Java Unit test framework) have a philosophy that if it is too simple to test, don't test it. I highly recommend reading their Best Practices FAQ, as it is fairly pragmatic.

TDD is a different process of writing your software. The basic premise behind unit testing is that you will spend less time in the debugger stepping through code, and more quickly figure out if your code change accidentally breaks something else in the system. That fits in with TDD. The TDD cycle is like this:

  1. Write a test
  2. Watch it fail (prove you have something to do)
  3. Write just what is needed to make the test pass--no more.
  4. Watch it pass (yay!)
  5. Refactor (make it better)
  6. Wash, rinse, and repeat

What is less obvious about applying TDD is that it changes the way your write code. By forcing yourself to think about how to test/validate that the code is working, you are writing testable code. And since we are talking unit testing, that usually means that your code becomes more modular. To me, modular and testable code is a big win up front.

Now, do you need to test things like C# properties? Imagine a property defined like this:

bool IsWorthTesting {get; set;}

The answer would be "no" it's not worth testing, because at this point you are testing the language feature. Just trust that the C# platform guys got it right. Besides, if it failed, what could you do to fix it?

Also, you will find that there are certain parts of your code that very well will be too much effort to test properly. That means don't do it, but make sure you test the code that uses/is used by the tricky problem:

  • Checked exceptions that can only occur if an install went bad. Java has a ton of these. You are required to write a catch block or declare the checked exception even if there is no way it can fail without hacking the installed files.
  • User interfaces. Finding the control under test, and invoking the right events to simulate a user's actions are very troublesome, and in some cases impossible. However, if you use the Model/View/Controller pattern, you can make sure your model and controllers are tested and leave the view part to manual testing.
  • Client/server interactions. This is no longer a unit test, and is now an integration test. Write all the parts that go up to sending and receiving messages over the wire, but don't actually go over the wire. A good approach is to reduce the responsibility of the code that actually talks over the wire to the raw communications. In your unit test code, mock communication object out to make sure the services are behaving as you expect.

Believe it or not, TDD will help you fall into a sustainable pace of development. It's not because of magic, but rather because you have a tight feedback loop and you are able to catch really dumb mistakes quickly. The cost of fixing those mistakes is essentially constant (at least enough for planning purposes) because the small mistakes never grow up to be big mistakes. Compare that with the bursty nature of code binge/debug purge sprints.

Source Link
Berin Loritsch
  • 46.5k
  • 7
  • 93
  • 164

The guys at JUnit (Java Unit test framework) have a philosophy that if it is too simple to test, don't test it. I highly recommend reading their Best Practices FAQ, as it is fairly pragmatic.

TDD is a different process of writing your software. The basic premise behind unit testing is that you will spend less time in the debugger stepping through code, and more quickly figure out if your code change accidentally breaks something else in the system. That fits in with TDD. The TDD cycle is like this:

  1. Write a test
  2. Watch it fail (prove you have something to do)
  3. Write just what is needed to make the test pass--no more.
  4. Watch it pass (yay!)
  5. Refactor (make it better)
  6. Wash, rinse, and repeat

What is less obvious about applying TDD is that it changes the way your write code. By forcing yourself to think about how to test/validate that the code is working, you are writing testable code. And since we are talking unit testing, that usually means that your code becomes more modular. To me, modular and testable code is a big win up front.

Now, do you need to test things like C# properties? Imagine a property defined like this:

bool IsWorthTesting {get; set;}

The answer would be "no" it's not worth testing, because at this point you are testing the language feature. Just trust that the C# platform guys got it right. Besides, if it failed, what could you do to fix it?

Also, you will find that there are certain parts of your code that very well will be too much effort to test properly. That means don't do it, but make sure you test the code that uses/is used by the tricky problem:

  • Checked exceptions that can only occur if an install went bad. Java has a ton of these. You are required to write a catch block or declare the checked exception even if there is no way it can fail without hacking the installed files.
  • User interfaces. Finding the control under test, and invoking the right events to simulate a user's actions are very troublesome, and in some cases impossible. However, if you use the Model/View/Controller pattern, you can make sure your model and controllers are tested and leave the view part to manual testing.
  • Client/server interactions. This is no longer a unit test, and is now an integration test. Write all the parts that go up to sending and receiving messages over the wire, but don't actually go over the wire. A good approach is to reduce the responsibility of the code that actually talks over the wire to the raw communications. In your unit test code, mock communication object out to make sure the services are behaving as you expect.

Believe it or not, TDD will help you fall into a sustainable pace of development. It's not because of magic, but rather because you have a tight feedback loop and you are able to catch really dumb mistakes quickly. The cost of fixing those mistakes is essentially constant (at least enough for planning purposes) because the small mistakes never grow up to be big mistakes. Compare that with the bursty nature of code binge/debug purge sprints.