开发者

Where to put functions I just need for testing?

I have a c开发者_StackOverflowouple Java classes which have blackbox test cases that just exercise the public API of the class. To write some whitebox test cases I needed to write some getters that are not part of the public API, but need to be visible to the test class.

How can I handle these functions?


You can make getters package default and place your test class in the same package.


The "package default" answer is a reasonable approach, but I question adding anything to main source for the sole purpose of testing. I also question the need for what you call "whitebox" testing of a class. If other objects always interact with objects of your class through its public API, why would you test anything besides that? My recommendation would be that you abandon this approach and stick to testing only your public API.


I often break out and expose the "code only" parts as public static methods, so the code can be unit tested. It works for me.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜