What kind of practices do you use to make your code more unit testing friendly?
相关问题
- Dependencies while implementing Mocking in Junit4
- How to unit test a reactive component where ngCont
- TestCafe - The browser always starts in clean slat
- Access for global variables JavaScript unit testin
- Name for a method that has only side effects
相关文章
- How to replace file-access references for a module
- How to mock methods return object with deleted cop
- What is a good way of cleaning up after a unit tes
-
EF6 DbSet
returns null in Moq - React testing library: Test attribute / prop
- React/JestJS/Enzyme: How to test for ref function?
- Should client-server code be written in one “proje
- Algorithm for maximizing coverage of rectangular a
Make sure all of your classes follow the Single Responsibility Principle. Single responsibility means that each class should have one and only one responsibility. That makes unit testing much easier.
To prepare your code to be testable:
To get the most out of your unit tests, consider the following:
Don't write untestable code
You don't necessarily need to "make your code more unit testing friendly".
Instead, a mocking toolkit can be used to make testability concerns go away. One such toolkit is JMockit.
Dependency injection seems to help.
I use Test-Driven Development whenever possible, so I don't have any code that cannot be unit tested. It wouldn't exist unless the unit test existed first.