开发者

How important is it to test single-line functions?

开发者 https://www.devze.com 2023-02-19 03:01 出处:网络
Should you or should yo开发者_JAVA百科u not test single-line functions?Today it\'s one line, next week it\'s twenty lines.

Should you or should yo开发者_JAVA百科u not test single-line functions?


Today it's one line, next week it's twenty lines.

Putting tests in place now warns you if you mistakenly break the behavior down the road.

Use your best judgment as to whether it's something that has any chance of changing in the future.


If they are part of your public interface then you should test them.


Some one-liners can be quite elegant/long.

I tend to not test "trivial" functions extensively, though there may be some tests (usually by inspection and one/two test cases) done just to make sure I've matched the documentation/specifications correctly (particularly if others may ever look at the doc and/or function).

Obviously, more complicated one-liners may require just as much testing as a "regular length" function (whatever regular length means to you).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号