Unit Testing Philosophy

I have a recipe method that I am trying to write using TDD. He mainly addresses various methods and sometimes makes decisions based on the results of these methods:

  public void HandleNewData(Data data)
  {
     var existingDataStore = dataProvider.Find(data.ID);
     if (data == null)
        return;

     UpdateDataStore(existingDataStore, data, CurrentDateTime);

     NotifyReceivedData(data);

     if (!dataValidator.Validate(data))
        return;

     //... more operations similar to above
  }

My knee-jerk reaction would be to start writing test cases when I verify that HandleNewData calls the methods described above, passing the expected arguments and returned when the method call fails. But for me it seems like it is a huge investment on time to encode such a test with virtually no actual benefit.

So what is the real benefit of writing such a test? Or is it really not worth the bother?

, , , .

+3
3

TDD , ( ).

, ", , ". , TDD. , , ...

  • unit test.
  • unit test, , .
  • , .

, 100% - , , , .

, , - , , - .

, HandleNewData(), - HandleNewData().

, . , . 25- .

+9

, , . , . .

, , , , - .

, , , , , , . , , ( !) .

, , TDD .

, , , .

+3

, " Legacy Code (TM)", . . - , .

, " ". ? !

, , "" "" . , "HandleNewData", ( )

  • checks the data (this should be step 2 from the appearance), etc.

As soon as I have existing behavior pinned by some automatic β€œflaws”, I can confidently make changes / improvements. It could also be that after reorganizing the project, the content type for HandleNewData is no longer needed. In what cases you can blow off these tests, however you cannot ignore the value of these tests between EXISTING-IMPROVED.

+1
source

All Articles