gpt4 book ai didi

eclipse - 写eclipse junit插件测试

转载 作者:行者123 更新时间:2023-11-28 19:45:36 24 4
gpt4 key购买 nike

我从哪里开始编写插件测试?我已经编写了一些玩具插件,并想开始使用我的插件进行 TDD。

最佳答案

如果您的插件是 RCP(富客户端平台)插件,使用 SWT,您可以使用 SWTBot .
这些测试可以封装到 JUnit 中:

Run-as-config-create


如果您的插件是基于 OSGi 的,您必须知道 OSGi 包运行它自己的类加载器,因此这些类似乎不在同一个包中。
参见“Is OSGi the enemy of JUnit tests?

Make your test plugin a fragment.
One problem is that other plugins cannot access classes defined in fragments (as Patrick Paulin points out in a more detailed discussion about fragments in unit tests).
Another problem is that plugin.xml in a fragment is ignored. And therefore you test plugin cannot contribute

摘自帕特里克的文章:

A fragments looks much like a plug-in from the outside. It is represented as a separate project in your workspace, it contains a manifest that describes its contents, it is built and deployed as a jar. What makes a fragment different is that it contributes it’s resources at runtime to a single host plug-in. The classes in the fragment are therefore loaded by the host plug-in’s classloader.

plugin unit test

By placing our unit tests in fragments, we can provide our tests access to the non-public methods of the classes under test. Also, because the source code and test code are actually part of the same plug-in, there are no issues related to non-exported packages. Test classes will have access to all packages in the plug-in, whether they are exported or not.

The main disadvantage to this fragment based approach is that it is difficult to aggregate unit tests into a master test suite. While it’s easy to create a test suite that includes the tests within a fragment, it’s not so easy to create a suite that includes the tests in multiple fragments.


如果你的插件只需要一些简单的测试,一个JUnit test套房足够了

Create a new test case BookTest in the package test.yourpackage, Right click on the package and choose "New > JUnit Test Case".

new test case

关于eclipse - 写eclipse junit插件测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/945279/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com