I'm struggling to find when to stop writting test cases using TDD.
Let's say a have to write a method that only accepts some strings, it can only accept the strings ['red', 'green', 'blue']
, it is required and can't be empty.
I write the first failing test, make it green, and so on and so forth until I have the test cases:
it('should accept red input', () => { /*...*/ }
it('should accept green input', () => { /*...*/ }
it('should accept blue input', () => { /*...*/ }
it('should not accept null input', () => { /*...*/ }
it('should not accept empty input', () => { /*...*/ }
At this point everything is passing, now should I call it a day and go or should I go and add a test if it fails for Purple
? Is it meaningful to add this test?
If it is, I still can name other 10 colours to test, should I consider them all too?
This example is simple, but there are cases with Regexes that have infinite combinations that I know that could be a problem and I can't add all test cases I can think of for time constraints. These are worst, because I don't know when to stop writing test code, and find when enough is enough.
I undertand I can't get a concrete anwser for this, but I would like to hear from experience what works most of the time.