2017-03-15 1 views
0

Ich habe ein Plugin-Projekt implementiert und möchten TestNG Registerkarte für Läufer Zweck in dieser Anwendung verwenden. Ich habe eine Lösung für JUnit aber in TestNG immer noch bin ich fest. Bitte helfen Sie aus dieser Situation heraus. finden freundlicherweise die JUnit Konfigurationscode Registerkarte unten:brauchen TestNG run Option in RCP-Anwendung

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); 
} 

Bitte vorschlagen.

Antwort

0

**** First TestTab.java Klasse erstellen, indem AbstractLaunchConfigurationTab erweitern ******

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; 
} 

*** erstellen Schnittstelle ITestNGPluginLauncherConstants *****

öffentliche Schnittstelle ITestNGPluginLauncherConstants {

String LEGACY_UI_TEST_APPLICATION =

"org.testng.eclipse.runtime.legacytestapplication";

String NON_UI_THREAD_APPLICATION =

"org.testng.eclipse.runtime.nonuithreadtestapplication";

String UI_TEST_APPLICATION =

"org.testng.eclipse.runtime.uitestapplication";

String CORE_TEST_APPLICATION =

"org.testng.eclipse.runtime.coretestapplication";

String TestNGProgramBlock_headless = "Keine Anwendung [Headless]";

String TAB_PLUGIN_TESTNG_MAIN_ID =

"org.testng.eclipse.plugin.launch.tab.main";

}

**** erstellen Klasse 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); 
        } 

}

**** erstellen Klasse TestNGProgramBlock.java erstreckt 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); 
} 

} 
}