2017-03-15 29 views
0

我已經實現了一個插件項目,並且希望在此應用程序中使用TestNG選項卡作爲運行程序用途。我有一個解決方案JUnit但在TestNG仍然卡住了。請幫助解決這種情況。請查看下JUnit配置標籤代碼:需要RCP應用程序中的TestNG運行選項

public void createTabs(ILaunchConfigurationDialog dialog, String mode) { 
    ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { 
     new JUnitLaunchConfigurationTab(), 
     new JavaArgumentsTab(), 
     new JavaClasspathTab(), 
     new JavaJRETab(), 
     new SourceLookupTab(), 
     new EnvironmentTab(), 
     new CommonTab() 
    }; 
    setTabs(tabs); 
} 

請建議。

回答

0

****首先創建TestTab.java類通過延伸AbstractLaunchConfigurationTab ******

private ILaunchConfigurationDialog fLaunchConfigurationDialog; 

private final TestNGMainTab testngLaunchTab; 

private Button runInUIThread; 

/** 
* Constructor to create a new junit test tab 
*/ 
public TestTab() { 

    this.testngLaunchTab = new TestNGMainTab(); 
} 

public void createControl(Composite parent) { 
    testngLaunchTab.createControl(parent); 

    Composite composite = (Composite) getControl(); 
createSpacer(composite); 
    createRunInUIThreadGroup(composite); 
} 

private void createRunInUIThreadGroup(Composite comp) { 
    runInUIThread = new Button(comp, SWT.CHECK); 
    runInUIThread.addSelectionListener(new SelectionAdapter() { 
     @Override 
     public void widgetSelected(SelectionEvent e) { 
      updateLaunchConfigurationDialog(); 
     } 
    }); 
    runInUIThread.setText(PDEUIMessages.PDEJUnitLaunchConfigurationTab_Run_Tests_In_UI_Thread); 
    GridDataFactory.fillDefaults().span(2, 0).grab(true, false).applyTo(runInUIThread); 
} 

private void createSpacer(Composite comp) { 
    Label label = new Label(comp, SWT.NONE); 
    GridDataFactory.fillDefaults().span(3, 0).applyTo(label); 
} 

public void initializeFrom(ILaunchConfiguration config) { 
    testngLaunchTab.initializeFrom(config); 
    updateRunInUIThreadGroup(config); 
} 

private void updateRunInUIThreadGroup(ILaunchConfiguration config) { 
    boolean shouldRunInUIThread = true; 
    try { 
     shouldRunInUIThread = config.getAttribute(IPDELauncherConstants.RUN_IN_UI_THREAD, true); 
    } catch (CoreException ce) { 
    } 
    runInUIThread.setSelection(shouldRunInUIThread); 
} 

public void performApply(ILaunchConfigurationWorkingCopy config) { 
    testngLaunchTab.performApply(config); 
    boolean selection = runInUIThread.getSelection(); 
    config.setAttribute(IPDELauncherConstants.RUN_IN_UI_THREAD, selection); 
} 

@Override 
public String getId() { 
    return IPDELauncherConstants.TAB_TEST_ID; 
} 

@Override 
public void activated(ILaunchConfigurationWorkingCopy workingCopy) { 
    testngLaunchTab.activated(workingCopy); 
} 

@Override 
public boolean canSave() { 
    return testngLaunchTab.canSave(); 
} 

@Override 
public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) { 
    testngLaunchTab.deactivated(workingCopy); 
} 

@Override 
public void dispose() { 
    testngLaunchTab.dispose(); 
} 

@Override 
public String getErrorMessage() { 
    return testngLaunchTab.getErrorMessage(); 
} 

@Override 
public Image getImage() { 
    return testngLaunchTab.getImage(); 
} 

@Override 
public String getMessage() { 
    return testngLaunchTab.getMessage(); 
} 

public String getName() { 
    return testngLaunchTab.getName(); 
} 

@Override 
public boolean isValid(ILaunchConfiguration config) { 
    return testngLaunchTab.isValid(config); 
} 

public void setDefaults(ILaunchConfigurationWorkingCopy config) { 
    testngLaunchTab.setDefaults(config); 
} 

@Override 
public void setLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) { 
    testngLaunchTab.setLaunchConfigurationDialog(dialog); 
    this.fLaunchConfigurationDialog = dialog; 
} 

***創建接口ITestNGPluginLauncherConstants *****

公共接口ITestNGPluginLauncherConstants {

字符串LEGACY_UI_TEST_APPLICATION =

「org.testng.eclipse.runtime.legacytestapplication」;

字符串NON_UI_THREAD_APPLICATION =

「org.testng.eclipse.runtime.nonuithreadtestapplication」;

字符串UI_TEST_APPLICATION =

「org.testng.eclipse.runtime.uitestapplication」;

字符串CORE_TEST_APPLICATION =

「org.testng.eclipse.runtime.coretestapplication」;

String TestNGProgramBlock_headless =「No application [Headless]」;

字符串TAB_PLUGIN_TESTNG_MAIN_ID =

「org.testng.eclipse.plugin.launch.tab.main」;

}

****創建類PluginTestNGMainTab.java *****

public class TestNGPluginTabGroup extends 
AbstractLaunchConfigurationTabGroup { 

    public TestNGPluginTabGroup() { 
    } 

    public void createTabs(ILaunchConfigurationDialog dialog, String mode) { 

     ILaunchConfigurationTab[] tabs = new ILaunchConfigurationTab[] { 

         new TestTab(), 
         new PluginTestNGMainTab(), 
         new JavaArgumentsTab(), 
         new PluginsTab(false), 
         new JavaArgumentsTab(), 
         new PluginsTab(), 
         new TracingTab(), 
         new ConfigurationTab(true), 
         new TracingTab(), 
         new EnvironmentTab(), 
         new CommonTab() 
     }; 

       setTabs(tabs); 
        } 

}

****創建類TestNGProgramBlock.java延伸ProgramBlock **** *

public TestNGProgramBlock(AbstractLauncherTab tab) { 

    super(tab); 
    } 

public void setDefaults(ILaunchConfigurationWorkingCopy config) { 

if (!LauncherUtils.requiresUI(config)) 
config.setAttribute(IPDELauncherConstants.APPLICATION, 
ITestNGPluginLauncherConstants.CORE_TEST_APPLICATION); 

else 
super.setDefaults(config); 
} 

protected String[] getApplicationNames() { 

TreeSet result = new TreeSet(); 
     result.add(ITestNGPluginLauncherConstants.TestNGProgramBlock_headless); 
String[] appNames = super.getApplicationNames();   
for (int i = 0; i < appNames.length; i++) { 
result.add(appNames[i]); 
} 
return appNames; 
} 
protected void initializeApplicationSection(ILaunchConfiguration config) 
throws CoreException { 
String application = 
config.getAttribute(IPDELauncherConstants.APPLICATION, (String)null); 
if(ITestNGPluginLauncherConstants.CORE_TEST_APPLICATION. 
equals(application)) 

fApplicationCombo.setText(ITestNGPluginLauncherConstants. 
TestNGProgramBlock_headless); 
else 

super.initializeApplicationSection(config); 
} 
protected void saveApplicationSection(ILaunchConfigurationWorkingCopy config) 
{ 
if(fApplicationCombo.getText().equals(ITestNGPluginLauncherConstants. 
TestNGPogramBlock_headless)){ 

String appName = fApplicationCombo.isEnabled() ? 

ITestNGPluginLauncherConstants.CORE_TEST_APPLICATION : null;  

config.setAttribute(IPDELauncherConstants.APPLICATION, appName);  

config.setAttribute(IPDELauncherConstants.APP_TO_TEST, (String)null); 
} 

} 
} 
相關問題