Is it Possible to test service methods with AEM Cloud?
We have many services which do things like call apis on external systems.
Currently, the only way we can test these end to en is to write servlets which call the services, and run the servlets via postman or similar.
What would be helpful is a way to:
1. use services in tests (without mocking them - using the full proper service)
2. be able to create a request to pass into services which are expecting it.
3. to have the tests only run on local builds, not on AEM builds (because AEM build servers wont have whitelisted IPs)
4. to be able to run a specific test only (via command line)
Which test framework is AEM using?
Obviously you cant just use a service in a test like you would in a servlet, e.g. this test wont work:
public class SomeServiceTest {
@Reference
private SomeService someService;
@Test
void someTest() throws Exception {
String result = someService.somecall(someparam);
}
}
We found an example like this:
@Rule public final AemContext context = new AemContext();
// register OSGi service context.registerService(MyClass.class, myService); // or alternatively: inject dependencies, activate and register OSGi service context.registerInjectActivateService(myService); // get OSGi service MyClass service = context.getService(MyClass.class);
But we cant resolve "Rule, and we are not sure if we need all 3 of those lines, or just one of them, and what MyClass is (is it the service class, or the test class, or another class)?