在Java中进行测试时是接口还是只有类?

时间:2022-09-25 12:10:45

What's the tendency with Java Tests? It's keep using interfaces how it's done with JMock or only classes how it's done with Mockito? Or both are ok? I really like Mockito because I feel it easier for write and understand test but sometimes I don't understand why with JMock you have to create an interface just with the purpose to use it on tests, What's your recommendation?

Java测试的趋势是什么?它一直在使用接口如何使用JMock或仅使用Mockito如何完成它?或两者都可以?我真的很喜欢Mockito,因为我觉得编写和理解测试更容易,但有时我不明白为什么使用JMock你必须创建一个接口只是为了在测试中使用它,你的建议是什么?

1 个解决方案

#1


3  

Use interfaces, for new self written code supporting a test driven design.

使用接口,用于支持测试驱动设计的新自编代码。

Use Mockito for code that was not desiged to be unit tested, or which has an extreme integrational character. Like code that starts up the whole system. If such a code was not deigned to be unit tested, then it is very difficult to introduce that afterwards. In that case mockito is the simpler task.

将Mockito用于未经过单元测试的代码,或者具有极端整合特性的代码。就像启动整个系统的代码一样。如果这样的代码没有被设计为单元测试,那么之后很难引入它。在那种情况下,mockito是更简单的任务。

#1


3  

Use interfaces, for new self written code supporting a test driven design.

使用接口,用于支持测试驱动设计的新自编代码。

Use Mockito for code that was not desiged to be unit tested, or which has an extreme integrational character. Like code that starts up the whole system. If such a code was not deigned to be unit tested, then it is very difficult to introduce that afterwards. In that case mockito is the simpler task.

将Mockito用于未经过单元测试的代码,或者具有极端整合特性的代码。就像启动整个系统的代码一样。如果这样的代码没有被设计为单元测试,那么之后很难引入它。在那种情况下,mockito是更简单的任务。