Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,298,141
Community Members
 
Community Events
165
Community Groups

Wired Integration Test: How to inject objects?

Edited

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.

1 answer

1 accepted

0 votes
Answer accepted
Fabian Lim Community Leader Dec 24, 2021

Thanks for the update.  Closing this ticket.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

154 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you