Hi Matthias,

("Sarosianer" is based on German grammar -- if at all, "Sarosians" or 
"Sarosistas" would sound more English)

You forgot to mention the most important thing for a unit test: Figure out what 
your unit is (you were just talking about "my test").
I figure that you might want to test your ProjectListManager [1].

> But since I need a REAL WorkspaceRoot this is not what I looking for or?

Why would you need a "real" object if you want to test the ProjectListManager 
logic?
Just provide the ctor with a stub and implement the methods you *actually* need.
(More on terms such as "mock" and "stub" here [2].)

You could do this in a very pragmatic way:
You create that stub with EasyMock, don't provide any method implementation, 
and run the test.
Any call on the stub will produce an error, and EasyMock's error message will 
tell you which method actually was called.
You can then equip your stub with a minimal implementation that is just enough 
to keep the unit-under-test running.
From what I can see in your current implementation, this would only be the 
"getProjects()" method which could return a hard-coded list of three fictional 
project.

You definitely don't need a "real" WorkspaceRoot, just as this test case [3] 
does not need a "real" File.
And you certainly don't need an STF test for this.

Cheers,
Franz

[1] 
http://saros-build.imp.fu-berlin.de/gerrit/#/c/2295/2/de.fu_berlin.inf.dpp.ui/src/de/fu_berlin/inf/dpp/ui/manager/ProjectListManager.java
[2] http://martinfowler.com/articles/mocksArentStubs.html
[3] 
https://github.com/saros-project/saros/blob/master@%7B2015-06-29%2018:00%7D/de.fu_berlin.inf.dpp/test/junit/de/fu_berlin/inf/dpp/project/SharedResourcesManagerTest.java#L67

-----Original Message-----
From: Matthias Bohnstedt [mailto:matthias.bohnst...@gmail.com] 
Sent: Monday, June 29, 2015 5:43 PM
To: dpp-devel@lists.sourceforge.net
Subject: [DPP-Devel] Setup JUnit tests in UI project

Hello Sarosianer, 

As the common HTML UI project is growing I want to write some tests for the it. 
This are not UI test (as there is no user action, or network needed), but just 
JUnit test. What I try to do is getting a ProjectListManager instance for my 
test. This manager needs an IWorkspaceRoot and I have no clue how to create a 
test WorkspaceRoot.

In Eclipse I normally would do something like:  
new EclipseWorkspaceRootImpl(ResourcesPlugin.getWorkspace().getRoot());[1]

But to keep this test IDE independent, I figured that I probably need some kind 
of injection here, but I don't know how to do it. This don't work (plm is null, 
running as JUnit, and JUnit Plug-In Test)

@Inject
private IWorkspaceRoot wRoot;

@Before
public void setUp() {
     ProjectListManager plm = new ProjectListManager(wRoot);
}

I looked at some existing JUnits,(for example the EclipseWorkspaceImplTest [2] 
) in Saros and find that we often use EasyMock to set up our tests. I read the 
guide but I am not quite sure how to start.[3] But since I need a REAL 
WorkspaceRoot this is not what I looking for or?

My questions are (besides any other hint and advice you have):
Can I even do this with a JUnit or do I need to start a STF test (or a 
JUnitPlug-inTest), since I need a real WorkspaceRoot to work with? 
How to get the same WorkspaceRoot as it would start Saros_STF_Alice?
How I would get a STF test running in the UI Project, since there should not be 
a dependence from the UI to Saros. 

I am kind of confused here how to even start.

Best
 Matthias


[1]http://stackoverflow.com/questions/27789115/setup-eclipse-workspace-in-java-code
[2]https://github.com/saros-project/saros/blob/bdd1edd9b49ecd8fd7ecbb09d04ae6fc8261deda/de.fu_berlin.inf.dpp/test/junit/de/fu_berlin/inf/dpp/filesystem/EclipseWorkspaceImplTest.java
[3] http://easymock.org/user-guide.html
------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
DPP-Devel mailing list
DPP-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dpp-devel

Reply via email to