How to start unit testing [message #1739801] |
Thu, 04 August 2016 10:24  |
Eclipse User |
|
|
|
I've created my projects using the wizards, and I'm missing the place to start using JUnit. If I create a JUnit test in a separate 'test' folder Eclipse kindly offers to add Junit to the required bundles, but of course that's not what I want.
To be honest, I've been using Gradle as a build system lately and there it is very easy as Gradle expects test to be in the test/java and the Eclipse Gradle plugin completely understands this too.
I opened the maven pom.xml, but I have the impression that all this XML isn't meant for humans to read.
What's the best way to start unit testing with JUnit?
|
|
|
|
|
|
Re: How to start unit testing [message #1739882 is a reply to message #1739860] |
Fri, 05 August 2016 06:46   |
Eclipse User |
|
|
|
The first test I tried to create was the following:
@Test
public void emptyDocument() {
RecipePartitioner partitioner = new RecipePartitioner();
Document document = new Document("");
partitioner.connect(document);
assertSame(partitioner, document.getDocumentPartitioner());
}
Where the implementation code is:
@Override
public void connect(IDocument document) {
this.document = document;
document.setDocumentPartitioner(this);
}
This triggers the document class to start partitioning with a SafeRunnable, which requires more of the OSGi framework.
Of course I can use Mockito to mock the document class, in Gradle I'd simply add a testCompile dependency. In the current setup I can of course add a mockito dependency as optional, but it seems a rather wierd strategy. I'm sure there must be another way.
@Dirk, In my Felix based OSGi project I'm do JUnit testing in a fairly standard, and easy, way. A bundle has a compile dependency on a service api, and I use mockito to mock the service. As with the Gradle conventions source is in src/main/java, tests are in src/test/java. Only the src/main/java end up in the OSGi bundle. I expect Maven to have a similar mechanism.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04837 seconds