TesterHQ - The Evil Tester Blog Aggregator

Aug 23, 2017 - 3 minute read - Instagram

Instagram Post - Unit Test When You Can

Original Instagram Post

I was writing some code yesterday for a REST API - starting complete from scratch.

I wrote my first test, and decided to refactor the hardcoded url and port into a configration class called server.

I did not create a Unit test first, I believed that since I already had an integration test against the live web server that this would be enough.

And indeed, my existing test failed. Meaning I had to go into debug mode to find out what was wrong.

Rather than debug, I created a Unit test class for the new server class. And that found my typo.

Fortunately I was reminded of this pathology in my development approach early.

It is too easy, when writing integration tests, to believe that because our supported test classes are ‘tested’ in passing then that is good enough. It often is good enough until:

  • we have to enter debug mode
  • we subject our code to an impartial code review
  • we have to reveal our shoddy code to the world

So:

  • Debugging slows us down.
  • Unit tests are fast to run.
  • If you refactor out a new class, which is tested in passing, then add unit tests for the new class

Refactored to Class? Remember to add Unit Tests for the new Class.

#TDD #Refactoring #Programming #SoftwareDevelopment #TestAutomation #RESTAPITesting #RESTAutomation #SoftwareTester #SoftwareTesting

I was writing some code yesterday for a REST API - starting complete from scratch.⠀ ⠀ I wrote my first test, and decided to refactor the hardcoded url and port into a configration class called server.⠀ ⠀ I did not create a Unit test first, I believed that since I already had an integration test against the live web server that this would be enough.⠀ ⠀ And indeed, my existing test failed. Meaning I had to go into debug mode to find out what was wrong.⠀ ⠀ Rather than debug, I created a Unit test class for the new server class. And that found my typo.⠀ ⠀ Fortunately I was reminded of this pathology in my development approach early.⠀ ⠀ It is too easy, when writing integration tests, to believe that because our supported test classes are 'tested' in passing then that is good enough. It often is good enough until:⠀ ⠀ - we have to enter debug mode⠀ - we subject our code to an impartial code review⠀ - we have to reveal our shoddy code to the world⠀ ⠀ So:⠀ ⠀ - Debugging slows us down.⠀ - Unit tests are fast to run.⠀ - If you refactor out a new class, which is tested in passing, then add unit tests for the new class⠀ ⠀ Refactored to Class? Remember to add Unit Tests for the new Class.⠀ ⠀ #TDD #Refactoring #Programming #SoftwareDevelopment #TestAutomation #RESTAPITesting #RESTAutomation #SoftwareTester #SoftwareTesting

A post shared by Software Testing Tips & Videos (@eviltester) on