An answer to my question about unit tests

I was browsing Gemini [1] when I came across a reponse to my unit test question [2]:

Sean Conner poses this question.

>

The answer is actually more sensible in C than it was in Smalltalk: a unit is a compilation unit. In C, it is a file.

>

Any changes to source will require changes to a file. Once a source file is altered, it may screw something up in the resultant binary. Therefore, there should be a unit test to check that the altered unit behaves as expected.

>

>

The easiest way to think of it in C is: assume make's view of the system.

>

“Re: What is a unit test [3]”

That is not a bad answer for C. In fact, it's probably not a bad answer for several different languages. The only clarification I can see being made is to only test non-static functions (functions that have visibility outside the file they're defined in) and not have specific tests for static functions (functions that only have visibility to code in the C file) to allow greater flexibility in implemenation and prevent tests from breaking too often.

[1] https://gemini.circumlunar.space/
[2] /boston/2022/10/08.1
[3] gemini://gemini.ctrl-/
Gemini Mention this post
Contact the author