When developing a plug-in to application, using the application API which doesn't run independently of the application, is unit-testing even a possibility? What are strategies to test a plug-in that is tightly integrated with an application?
在为应用程序开发插件时,使用不是独立于应用程序运行的应用程序API,甚至是单元测试的可能性?测试与应用程序紧密集成的插件的策略是什么?
2 个解决方案
#1
1
Most people miss the point of about mock objects. They aren't about testing, they're about interface discovery. Or as Michael Feather's put it a different way in a recent blurb: API Wrapping.
大多数人都忽略了关于模拟对象的观点。它们不是关于测试,而是关于接口发现。或者正如Michael Feather在最近的一篇文章中所说的那样:API Wrapping。
Don't code directly against the api. Instead create your own interfaces that abstract that api and then write tests for your code.
不要直接针对api编码。而是创建自己的接口来抽象api,然后为您的代码编写测试。
I've done this when writing plugins for Eclipse and the results were far better than I had expected ahead of time.
我在为Eclipse编写插件时已经这样做了,结果远远超过了我预期的预期。
#2
2
Abstract out the host API with interfaces, and test against a mock host.
使用接口抽象出主机API,并针对模拟主机进行测试。
The key is that your logic is tested with the characteristic data that the host might provide.
关键是您的逻辑使用主机可能提供的特征数据进行测试。
If you have a code example, I can probably give you a better answer.
如果你有一个代码示例,我可以给你一个更好的答案。
#1
1
Most people miss the point of about mock objects. They aren't about testing, they're about interface discovery. Or as Michael Feather's put it a different way in a recent blurb: API Wrapping.
大多数人都忽略了关于模拟对象的观点。它们不是关于测试,而是关于接口发现。或者正如Michael Feather在最近的一篇文章中所说的那样:API Wrapping。
Don't code directly against the api. Instead create your own interfaces that abstract that api and then write tests for your code.
不要直接针对api编码。而是创建自己的接口来抽象api,然后为您的代码编写测试。
I've done this when writing plugins for Eclipse and the results were far better than I had expected ahead of time.
我在为Eclipse编写插件时已经这样做了,结果远远超过了我预期的预期。
#2
2
Abstract out the host API with interfaces, and test against a mock host.
使用接口抽象出主机API,并针对模拟主机进行测试。
The key is that your logic is tested with the characteristic data that the host might provide.
关键是您的逻辑使用主机可能提供的特征数据进行测试。
If you have a code example, I can probably give you a better answer.
如果你有一个代码示例,我可以给你一个更好的答案。