Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

0 answers

Suggest an answer

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

🏑 Atlympic Event: Confluence

Hello Community!  Quick disclaimer: We are running a contest on Community (The Atlympics!) from July 23rd - August 8th of 2021. If you are interested in participating in this contest (prizes! ...

424 views 16 13
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