Disclamer: clearly this could (and should) be done in a unit-test, but it’s created as a minimum example, as I’m struggling with the complete basics of how to reference a class from an integration test. The example in the plugin tutorials simply references the boilerplate test already present, and event the part about adding a “traditional integration test” simply does a println
and an bogus assert.
To create the minimum example, I’ve created a new plugin with atlas-create-jira-plugin
.
I have this basic class: HelperClass
containing:
package com.nicolaj.cat.impl;
public class HelperClass {
private String name;
public HelperClass(String name) {
this.name = name;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
I would like to write a test for this that sets a state, reads it, changes the state and validates that the state has been changed. HelperClassTest
contains:
package it.com.nicolaj.cat;
import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner;
import com.nicolaj.cat.impl.HelperClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertFalse;
@RunWith(AtlassianPluginsTestRunner.class)
public class HelperClassTest {
@Test
public void someTest()
{
// Arrange
HelperClass hc = new HelperClass("somestring");
String before = hc.getName();
// Act
hc.setName("newstring");
String after = hc.getName();
// Assert
assertFalse("The name hasn't changed!", before.equals(after));
}
}
If I just run atlas-integration-test
, I get an error NoClassDefFoundError
for HelperClass
. On Google I found the article: NoClassDefFoundError. It says to “make sure the class and package name are correct and that the class is declared as a component
in its atlassian-plugin.xml
.”
- The class and package name is correct. The class is called
HelperClass
and it’s in the packagecom.nicolaj.cat.impl
which is imported withimport com.nicolaj.cat.impl.HelperClass;
. - When I add it as a component in
atlassian-plugin.xml
like below: (fullatlassian-plugin.xml
-file in the bottom)
...
<component key="helperClass" class="com.nicolaj.cat.impl.HelperClass" />
...
however, I get another error:
...
No tests found in class [it.com.nicolaj.cat.HelperClassTest]: No tests found in class [it.com.nicolaj.cat.HelperClassTest]
...
With the stack trace:
...
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running it.com.nicolaj.cat.HelperClassTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] [talledLocalContainer] jan. 09, 2019 3:38:21 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
[INFO] [talledLocalContainer] INFO: Initiating Jersey application, version 'Jersey: 1.19 02/11/2015 03:25 AM'
[INFO] [talledLocalContainer] jan. 09, 2019 3:38:21 PM com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
[INFO] [talledLocalContainer] INFO: Loading wadlGenerator com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
[INFO] [talledLocalContainer] jan. 09, 2019 3:38:21 PM com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
[INFO] [talledLocalContainer] INFO: Loading wadlGenerator com.atlassian.plugins.rest.doclet.generators.grammars.WadlGrammarsAdaptor
[INFO] [talledLocalContainer] jan. 09, 2019 3:38:21 PM com.sun.jersey.api.wadl.config.WadlGeneratorLoader loadWadlGenerator
[INFO] [talledLocalContainer] INFO: Loading wadlGenerator com.atlassian.plugins.rest.doclet.generators.resourcedoc.AtlassianWadlGeneratorResourceDocSupport
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.286 sec <<< FAILURE!
No tests found in class [it.com.nicolaj.cat.HelperClassTest] Time elapsed: 2.285 sec <<< ERROR!
java.lang.Exception: No tests found in class [it.com.nicolaj.cat.HelperClassTest]
at com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner.runViaRestCall(AtlassianPluginsTestRunner.java:125)
at com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner.run(AtlassianPluginsTestRunner.java:75)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
...
My atlassian-plugin.xml
-file looks like this:
<atlassian-plugin key="${project.groupId}.${project.artifactId}-tests" name="${project.name}" plugins-version="2">
<plugin-info>
<description>${project.description}</description>
<version>${project.version}</version>
<vendor name="${project.organization.name}" url="${project.organization.url}" />
</plugin-info>
<!-- from our base plugin -->
<component-import key="myComponent" interface="com.nicolaj.cat.api.MyPluginComponent"/>
<!-- from the product container -->
<component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties" />
<component key="helperClass" class="com.nicolaj.cat.impl.HelperClass" />
</atlassian-plugin>
And my project structure looks like this:
Any advice would be helpful.
PS: I know that the above test should just be a unit-test, but it’s created as a minimum example of “an integration test that is not being picked up by junit.”