Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Call JUnit Plugin from other Eclipse Plugin
icon5.gif  Call JUnit Plugin from other Eclipse Plugin [message #755837] Wed, 09 November 2011 18:44 Go to next message
Zé  arlos is currently offline Zé arlosFriend
Messages: 15
Registered: October 2011
Junior Member
I am developing for Eclipse, and one feature is run JUnit tests. Now my plugin detect JUnit tests on a project in workspace and after this I want to call JUnit to run this tests.

I heard about ILaunch, ILaunchConfigurationDelegate, JUnitLaunchConfigurationDelegate but I cannot found an example of this and also I'm not sure if I have to use this!



Thanks in advance Razz
Re: Call JUnit Plugin from other Eclipse Plugin [message #756037 is a reply to message #755837] Thu, 10 November 2011 14:57 Go to previous messageGo to next message
Zé  arlos is currently offline Zé arlosFriend
Messages: 15
Registered: October 2011
Junior Member
If I put this
<shortcut
			label="JUnitTestShortcut"
			icon="icons/elcl16/run.gif"
			class="org.eclipse.jdt.junit.launcher.JUnitLaunchShortcut"
			modes="run, debug"
			id="com.ui.junitShortcut">
			<contextualLaunch>
				<enablement>
					<with variable="selection">
						<test property="com.plugin.ui.launchable" args="org.eclipse.jdt.junit.junitShortcut" />
					</with>
				</enablement>
			</contextualLaunch>
		</shortcut>

in plugin.xml I can call JUnit with all tests present in selected Project.

But I don't want execute all tests in some project, I just want some of them... How can I send some tests to JUnit Plugin ? Confused


--
Cheers, Smile
Re: Call JUnit Plugin from other Eclipse Plugin [message #756052 is a reply to message #756037] Thu, 10 November 2011 16:30 Go to previous messageGo to next message
Zé  arlos is currently offline Zé arlosFriend
Messages: 15
Registered: October 2011
Junior Member
New approach:

IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("LittleProject");
JUnitLaunchConfigurationDelegate delegate = new JUnitLaunchConfigurationDelegate();
ILaunchConfiguration configuration = null;

try {
    configuration = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations()[3]; // Should work on this

    ILaunch launch = configuration.launch(ILaunchManager.RUN_MODE, null);
    delegate.launch(configuration, ILaunchManager.RUN_MODE, launch, null);
}
catch (Exception e) {
    e.printStackTrace();
}


getLaunchConfigurations()[3] it's a run configuration that I have in workspace. It call the JUnit View with one of the test present in Java Project 'LittleProject'. This solution is more closer... but not perfect.... Confused

If I changed the line:
configuration = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations()[3];

to
configuration = getJavaApplicationType().newInstance(project, "Launch");
...
private ILaunchConfigurationType getJavaApplicationType() {
    return DebugPlugin
        .getDefault()
        .getLaunchManager()
        .getLaunchConfigurationType("org.eclipse.jdt.junit.launchconfig");
	}


But the program returns "Invalid project specified."
Changing the ConfigurationType to "org.eclipse.jdt.launching.localJavaApplication", program returns "Main type not specified"

How can I create a new Configuration in code, that select only the tests I want and after launch this configuration?
Re: Call JUnit Plugin from other Eclipse Plugin [message #756111 is a reply to message #756052] Thu, 10 November 2011 23:54 Go to previous messageGo to next message
Zé  arlos is currently offline Zé arlosFriend
Messages: 15
Registered: October 2011
Junior Member
(update)

When I execute this piece of code:
Object[] segments = new Object[2];
segments[0] = // JUnit Test Class 1
segments[1] = // JUnit Test Class 2

TreePath treepath = new TreePath(segments);
TreeSelection treeselection = new TreeSelection(treepath);

JUnitLaunchShortcut j = new JUnitLaunchShortcut();
j.launch(treeselection, ILaunchManager.RUN_MODE);


Eclipse/JUnit Plugin only execute JUnit Test Class 2, perhaps execute the two Test Class but only show at JUnit View the last Test Class (maybe)....

What you think? How can I 'launch' the all Test Class? Confused

EDIT:

I check the JUnitLaunchShortcut source code and found that class only execute the last Test that I send.

If I send a JAVA_PROJECT the JUnitLaunchShortcut execute all Test present in project, if I send a PACKAGE_FRAGMENT the JUnitLaunchShortcut execute only the Tests in present in package, but if I send a set of COMPILATION_UNIT (Classes) JUnitLaunchShortcut only execute the last Class that I sent...

How can I change the original JUnitLaunchShortcut source code to execute all test that I send? Confused


Cheers. Wink

[Updated on: Fri, 11 November 2011 17:03]

Report message to a moderator

Re: Call JUnit Plugin from other Eclipse Plugin [message #756290 is a reply to message #756111] Fri, 11 November 2011 19:27 Go to previous messageGo to next message
Zé  arlos is currently offline Zé arlosFriend
Messages: 15
Registered: October 2011
Junior Member
anyone?!
Re: Call JUnit Plugin from other Eclipse Plugin [message #756394 is a reply to message #756290] Sat, 12 November 2011 17:00 Go to previous message
Zé  arlos is currently offline Zé arlosFriend
Messages: 15
Registered: October 2011
Junior Member
After a lot of hours, I think it is impossible to do what I want...

RunConfiguration of Eclipse doesn't support selection of several Test Cases! Only runs a SingleTestClass or one Project, Package or SourceFolder, doesn't run multiple Test Cases from several packages. Crying or Very Sad Crying or Very Sad

[Updated on: Sat, 12 November 2011 17:08]

Report message to a moderator

Previous Topic:graphic Equalizer
Next Topic:QuickfixProcessor vs. Eclipse UI Quick Fix
Goto Forum:
  


Current Time: Thu Apr 25 23:09:55 GMT 2024

Powered by FUDForum. Page generated in 0.03642 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top