Aivar
Aivar

Reputation: 7012

JUnit testing custom Eclipse builders

I have created an extra builder for Java projects.

I'm trying to test it automatically via JUnit test that changes and refreshes a project file and expects automatic builder to kick in. Unfortunately this doesn't happen.

I can access and modify Workspace from that test but I don't know how to deal with builders (or GUI elements). I also tried to check "Run in UI thread" in junit test's debug configuration but no success.

What's the proper way to do this kind of testing? (I'd like to avoid learning TPTP, if possible -- looks too heavy).

How to initiate "Project -> Clean" command from my tests? Or how to execute any UI command? I suppose there are some threading issues to take care of.

Upvotes: 0

Views: 280

Answers (1)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28737

I think you are looking for the command:

ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null);

and ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null);

The first will initiate a clean, and then a build on the entire workspace. The second will initiate only a clean.

Alternatively, if you have access to an IProject object, you can call build on that.

Upvotes: 1

Related Questions