Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Writing unit tests for JUnit launches
Writing unit tests for JUnit launches [message #1277862] Wed, 26 March 2014 15:08 Go to next message
Ricardo Gladwell is currently offline Ricardo Gladwell
Messages: 12
Registered: July 2009
Location: London, UK
Junior Member

I'm trying to write an end-to-end test fixture using the Eclipse PDE JUnit runner to verify that a sample launch is running successfully. The following should fail:

    public void testTestRunner() throws Exception {
        // given
        ILaunchConfiguration configuration = launchManager.getLaunchConfiguration(project.getFile("test.launch"));

        // when
        ILaunch launch = configuration.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());

        // then
        while(!launch.isTerminated()) {
            sleep(500);
        }
        for(IProcess process : launch.getProcesses()) {
            assertEquals("runner process " + process + " failed", 0, process.getExitValue());
        }
    }


I deliberately wrote a test fixture in the example project so it would fail. But this passes!

How are other people writing JUnit PDE tests for their customised launches? Without mocking?
Re: Writing unit tests for JUnit launches [message #1278249 is a reply to message #1277862] Thu, 27 March 2014 04:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26088
Registered: July 2009
Senior Member
Ricardo,

I'm not sure JDT is the best place to ask about this, but I'm not sure
of a better place. Is the list of processes non-empty? I.e., perhaps
an empty list is also an indication of failure...

On 26/03/2014 4:08 PM, Ricardo Gladwell wrote:
> I'm trying to write an end-to-end test fixture using the Eclipse PDE
> JUnit runner to verify that a sample launch is running successfully.
> The following should fail:
>
> public void testTestRunner() throws Exception {
> // given
> ILaunchConfiguration configuration =
> launchManager.getLaunchConfiguration(project.getFile("test.launch"));
>
> // when
> ILaunch launch = configuration.launch(ILaunchManager.RUN_MODE,
> new NullProgressMonitor());
>
> // then
> while(!launch.isTerminated()) {
> sleep(500);
> }
> for(IProcess process : launch.getProcesses()) {
> assertEquals("runner process " + process + " failed", 0,
> process.getExitValue());
> }
> }
>
> I deliberately wrote a test fixture in the example project so it would
> fail. But this passes!
>
> How are other people writing JUnit PDE tests for their customised
> launches? Without mocking?
>
Re: Writing unit tests for JUnit launches [message #1278451 is a reply to message #1278249] Thu, 27 March 2014 11:02 Go to previous messageGo to next message
Ricardo Gladwell is currently offline Ricardo Gladwell
Messages: 12
Registered: July 2009
Location: London, UK
Junior Member

Hi Ed,

The array returned by launch.getProcesses() is definitely non-empty. If I put an assert like this:

assertTrue(launch.getProcesses().length > 0)


It would pass.

Any ideas, thoughts or suggestions would be great Smile
Re: Writing unit tests for JUnit launches [message #1279009 is a reply to message #1278451] Fri, 28 March 2014 05:42 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26088
Registered: July 2009
Senior Member
Ricardo,

I really have no clue, so maybe someone else with a clue will comment.
However, if I were trying to figure this out myself and no one helped
me, I would try to figure out how the JUnit view knows what to display.
Alt-Shift-F1 (plug-in spy) will give you information about what's
implementing the things you see in the IDE. Using that, I would start
looking at how org.eclipse.jdt.internal.junit.ui.TestRunnerViewPart
works its magic.

On 27/03/2014 12:02 PM, Ricardo Gladwell wrote:
> Hi Ed,
>
> The array returned by launch.getProcesses() is definitely non-empty.
> If I put an assert like this:
>
> assertTrue(launch.getProcesses().length > 0)
>
> It would pass.
>
> Any ideas, thoughts or suggestions would be great :)
Previous Topic:Reconciling the document partitioner, reconcilers and resource builder
Next Topic:Project-specific Compiler Warning Settings
Goto Forum:
  


Current Time: Wed Oct 01 22:35:50 GMT 2014

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

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