Do I have to write tests before they compile?

I am trying to execute a TDD workflow for one of my open source projects. This is an API for other programmers.

Thus, one key aspect, as well as creating a “work” API, also determines how it will be consumed. I heard that some people say that writing tests before they are compiled is a waste of time and a penchant for constantly rewriting until the API is stable. I also heard that he should follow this way:

  • Write tests that will not compile
  • Make compilation
  • Make it green.

I try to follow this workflow, but in the end I get some strange things. For example, in my API, I have two methods:

Handles(string pattern); //had this one already
Handles(IPatternMatcher pattern); //needed this one

I needed to get the second form of the method added to my API. So, I ended up with a dead simple test, for example:

public void Handles_SupportsIPatternMatcher()
{
  var api=new MyAPI();
  api.Handles(new TestPatternMatcher());
}

It seems that after its implementation will be lost.

Should I continue to complete this workflow, or are there ways to improve it? How can I refuse to write tests that mostly check for compiler errors? Since this is a public API, should I worry about trials like this?

+5
source share
2 answers

No.

Do not write code that checks if the compiler is working. Such tests make a lot of sense if you use dynamic languages ​​(or dynamic functions in a static language), where they will actually tell you that you forgot something, or reorganized something into a failed unit test.

unit test , . , . .

+3

resharper, Handles, IPatternMatcher. TDD - , . , , , . . - , , .

+1