Should source code know it's being tested? [closed]

我的未来我决定 提交于 2019-12-25 05:28:26

问题


I have a complex codebase with tight couplings between functions and I am not able to write unit tests easily.

Should source code know about testing environment, should it know it's being tested?

To indicate it's being tested or so can be easily via global flag but I have a fear it may cause a bigger mess in the long run.


回答1:


In short, no.

Your code should be written in such a fashion that it is testing-agnostic. What I mean is that it shouldn't care if it is being tested or not. Because of your 'tight couplings' I would suggest that you do your testing as manually as you can since that would give you the best litmus test of it working as expected.

Also, if your code is implemented well enough it would also be environment agnostic. Whatever environment you test in should be as close to real-world as possible.



来源:https://stackoverflow.com/questions/17348260/should-source-code-know-its-being-tested

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!