Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How to write a test for method having eclipse job?
How to write a test for method having eclipse job? [message #791913] Mon, 06 February 2012 12:10 Go to next message
Ramesh Gunjal is currently offline Ramesh GunjalFriend
Messages: 5
Registered: February 2012
Junior Member
Hello,

I am new to Eclipse/Java/JUnit. I have an RCP application and my job is to write tests for its functionality. I want to write a test for methos which shedules eclipse job (running some program in background)

I cant write test for such method because test get completed before the main threads jobs get finished and I cant check result of job.
-------------------
@Test
public void testRunTimeline() {
Session session = new Session()
Runner runner = new Runner();
runner.runJob(session)

//Need to wait for job to finish
assertFail("No result found", session.result().isEmpty);

}
-------------------

The test always fail because result is empty.

Does someone know how to handle this. Any code sample will be very helpfull

--
God bless you,
Ramesh
Re: How to write a test for method having eclipse job? [message #791940 is a reply to message #791913] Mon, 06 February 2012 12:47 Go to previous message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 2012-02-06 13:10, Ramesh Gunjal wrote:
> I am new to Eclipse/Java/JUnit. I have an RCP application and my job is
> to write tests for its functionality. I want to write a test for methos
> which shedules eclipse job (running some program in background)
>
> I cant write test for such method because test get completed before the
> main threads jobs get finished and I cant check result of job.
> -------------------
> @Test
> public void testRunTimeline() {
> Session session = new Session()
> Runner runner = new Runner();
> runner.runJob(session)
>
> //Need to wait for job to finish
> assertFail("No result found", session.result().isEmpty);
>
> }
> -------------------
>
> The test always fail because result is empty.
>
> Does someone know how to handle this. Any code sample will be very helpfull

How would you write a unit test for a function called in another thread
by using Java Thread API? When you have solved this problem you can
apply the same solution to a function called by an Eclipse job.

Hint: One possible way of doing this is to invoke the join() function
after scheduling the job. I don't know, what you actually want to test,
therefore you might need to reflect on whether this is a reasonable
procedure.

HTH & Greetings from Bremen,

Daniel Krügler
Previous Topic:How to get rid of Java perspective
Next Topic:Is WorkbenchResolutionGenerator description implemented?
Goto Forum:
  


Current Time: Tue Apr 16 07:47:18 GMT 2024

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

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

Back to the top