2017-03-15 17 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

****まず

パブリックインターフェイスITestNGPluginLauncherConstants {

*****インタフェースITestNGPluginLauncherConstantsを作成*** 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; 
} 

によってTestTab.javaクラスを作成

文字列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"。

文字列TestNGProgramBlock_headless = "アプリケーションなし[ヘッドレス]";

文字列TAB_PLUGIN_TESTNG_MAIN_ID =

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

}

**** TestNGProgramBlock.javaはProgramBlockを拡張するクラスを作成****

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

}

*****クラスPluginTestNGMainTab.javaを作成**** *

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

} 
} 
関連する問題