I want to write an integration test for my plugin. Following the Atlassian tutorial, I can get a simple integration test run successfully. As soon as I need some classes from the Confluence environment for my test, I am stuck. According to the second section of the above mentioned tutorial, I can use the constructor of the test class to get these injected. I tried that, using the following code:
public class MyTest {
private final UserManager userManager;
private final ActiveObjects ao;
//@Inject
@Autowired
public MyTest(@ComponentImport UserManager userManager, @ComponentImport ActiveObjects ao) {
this.userManager = userManager;
this.ao = ao;
}
@Test
public void runTest() { }
}
the test fails when run from the Atlassian Plugin Test Console, and in the browser developer console, I find the following in the response for the test API call sent from the console:
...
fThrownException: {detailMessage: "Test class should have exactly one public zero-argument constructor",…}
detailMessage: "Test class should have exactly one public zero-argument constructor"
...
I tried both Annotations, `@Autowired` and `@Inject`, getting the same result.
I also tried to add an empty constructor in addition to the one shown above so that I have two constructors in the class now:
public MyTest() {
this.userManager = null;
this.ao = null;
}
This avoids the error, but no test is executed, hence this does not help.
Any idea how I can get references to environment objects like UserManager or ActiveObjects in an integration test?
EDIT:
As I found no solution, I gave up on using the Atlassian provided integrated integration tests, and as an alternative set up a separate project for my integration tests just testing the REST calls using REST Assured.
Thanks for the update. Closing this ticket.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.