TDD - What tests should be written for this function?

I read that at first I should write simple basic tests and gradually move on to more complex ones. What tests (in order) should I write for the next function?

List.syncWithList(lst) function

  • should add any elements to the list that are not on the list but are in lst
  • should remove any items in the list that are not in lst
  • replace any items in the list that have different version tags than those listed in lst
  • do not replace any items in the list that have the same version tags as those specified in lst
+4
source share
1 answer

You have your main list of tests. You just provided them to us. At a minimum level, you should verify that all functional requirements are met (for example, the four questions you gave us in the question).

This includes cross cases, such as empty lists (on one and both sides), identical lists, etc.

The easiest way to get started is to add the following:

  • an empty list on both sides.
  • identical lists.
  • empty list on the left with a right list with one item to add.
  • singleton list on the left with an empty right list to delete.
  • previous two tests, but with five-element lists on the one hand.
  • replacing one item in a singleton left list.
  • replacement of one element in the five-element left list.
  • replacement of three elements in the five-element left list.
  • Verify that replacements are not performed with identical version tags.

and then add more when you cause individual problems.

And I can’t stress this: automate testing! You will find that testing is much easier if you can just click a button and view the results. Each time you click on an error, add a test that would catch this error in the test suite above and click the button to check it.

We have testing right down to the visual arts. With one command, the whole process starts, which dumps the databases, loads them with known data, starts our tests, compares the result with previous successful tests, etc.

If we had to do all this manually when we made the changes, we would soon take the whole idea. Automating everything, testing is a breeze.

+8
source

Source: https://habr.com/ru/post/1315362/


All Articles