java - 在 Eclipse 中创建自定义 JUnit 启动配置
问题描述
我正在尝试创建自定义 JUnit 插件测试启动配置。
我已经扩展了类JUnitWorkbenchLaunchShortcut
并重写了createLaunchConfiguration()
编写自定义配置的方法。
@Override
protected ILaunchConfigurationWorkingCopy createLaunchConfiguration(final IJavaElement element)
throws CoreException {
ILaunchConfigurationWorkingCopy configuration = super.createLaunchConfiguration(element);
configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS,
XMX2048M_XX_USE_PARALLEL_GC_DOSGI_FRAMEWORK_EXTENSIONS_ORG_ECLIPSE_EQUINOX_WEAVING_HOOK_DEQUINOX_USE_DS_TRUE);
configuration.setAttribute(IPDELauncherConstants.USE_PRODUCT, false);
configuration.setAttribute(IPDELauncherConstants.APPLICATION, "org.eclipse.ui.ide.workbench");
configuration.setAttribute(IPDELauncherConstants.USE_DEFAULT, false);
configuration.setAttribute(IPDELauncherConstants.AUTOMATIC_ADD, false);
addDependencies(configuration);
return configuration;
}
private void addDependencies(final ILaunchConfigurationWorkingCopy configuration) throws CoreException {
PluginModelNameBuffer wBuffer = new PluginModelNameBuffer();
PluginModelNameBuffer tBuffer = new PluginModelNameBuffer();
Set<IPluginModelBase> addedModels = new HashSet<>();
String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IPluginModelBase model = PluginRegistry.findModel(project);
wBuffer.add(model);
addedModels.add(model);
IPluginModelBase[] externalModels = PluginRegistry.getExternalModels();
for (IPluginModelBase externalModel : externalModels) {
String id = externalModel.getPluginBase().getId();
if (id != null) {
switch (id) {
case "org.eclipse.ui.ide.application":
case "org.eclipse.equinox.ds":
case "org.eclipse.equinox.event":
tBuffer.add(externalModel);
addedModels.add(externalModel);
break;
default:
break;
}
}
}
TreeSet<String> checkedWorkspace = new TreeSet<>();
IPluginModelBase[] workspaceModels = PluginRegistry.getWorkspaceModels();
for (IPluginModelBase workspaceModel : workspaceModels) {
checkedWorkspace.add(workspaceModel.getPluginBase().getId());
}
EclipsePluginValidationOperation eclipsePluginValidationOperation = new EclipsePluginValidationOperation(
configuration);
eclipsePluginValidationOperation.run(null);
while (eclipsePluginValidationOperation.hasErrors()) {
Set<String> additionalIds = DependencyManager.getDependencies(addedModels.toArray(), true, null);
if (additionalIds.isEmpty()) {
break;
}
additionalIds.stream().map(PluginRegistry::findEntry).filter(Objects::nonNull).map(ModelEntry::getModel)
.forEach(addedModels::add);
for (String id : additionalIds) {
IPluginModelBase plugin = findPlugin(id);
if (!plugin.getPluginBase().getId().endsWith("tests")) {
if (checkedWorkspace.contains(plugin.getPluginBase().getId())) {
wBuffer.add(plugin);
} else {
tBuffer.add(plugin);
}
}
}
eclipsePluginValidationOperation.run(null);
}
configuration.setAttribute(IPDELauncherConstants.SELECTED_WORKSPACE_PLUGINS, wBuffer.toString());
configuration.setAttribute(IPDELauncherConstants.SELECTED_TARGET_PLUGINS, tBuffer.toString());
}
protected IPluginModelBase findPlugin(final String id) {
ModelEntry entry = PluginRegistry.findEntry(id);
if (entry != null) {
return entry.getModel();
}
return null;
}
}
启动配置完全按照其应有的方式创建,但在打开工作台时插件测试不会运行。仅当打开运行配置对话框并单击其中的run
按钮时才会执行测试。
解决方案
推荐阅读
- sql-server - 标准 2019 版的一个 SQL 独立实例上的 3000 个数据库,在 Windows Server 上
- reactjs - 多次调用 Pubnub 消息和存在处理程序
- firefox - 如何让 FireFox 在不加载页面的情况下接收后台推送通知?
- visual-studio-code - 未找到 VSCode 构建任务命令
- javascript - 如何使用护照本地猫鼬使用多个数据进行身份验证?
- database - POST 路由器在向客户端发送数据时卡住(无响应)
- python - 我想要结果,python 硒过滤器
- javascript - 为什么将变量的条件设置为未定义会出错?
- sparql - Wikidata / Sparql 返回一系列数字
- collections - Postman Collection-通过代码设置授权标头