Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Unit test(using osgi-mock.junit5) to read osgi config fails to build

Avatar

Level 1

Unit test fails with message

org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found for class

 

 I have written a unit test using OSGi-mock-junit5 but when I try to build the project(mvn clean install), I get the failure message "org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found for class"

 

I found similar post  https://cqdump.wordpress.com/2019/01/14/writing-unit-tests-for-aem-part-2-maven-setup/ & followed the steps to fix it but it's still the same issue.

 

anyone has got any idea?

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 1
mvn clean package -DskipTests

 

Worked for me. If you use intelliJ or another IDE, make sure to invalidate its caches. An IDE behaves differently from Terminal, it has its own "environment" along with its own caching mechanisms.

View solution in original post

6 Replies

Avatar

Employee

After following the POM updates in the linked blog update, try the following maven commands:

 

$ mvn clean package -DskipTests
$ mvn test

 IIRC I would occasionally run into this issue if the OSGi SCR metadata XML files weren't generated when the tests ran; doing the `mvn clean package` would generate this for me and then allow my tests to run (you could try dialing it back to `mvn clean compile` or other phases/goals)

Avatar

Level 1

Thank you for your reply. I tried following command & it worked.

mvn clean package -DskipTests

it worked but

"mvn test" and "mvn clean package" failed.  However

"mvn clean compile" worked so issue is the execution of test is not working & throws that error.

Do you have anything in your <PROJECT>>/core/target/classes/OSGI-INF folder? You should have a number of XML files, and a metatype folder with more XMLs. Does this exist?

Avatar

Level 1

Hi,

Yes both the folders are there, the XML files are in both but it doesn't have an XML file for the service written using OSGi annotations.

They have XML files for the services written using maven SCR annotations.

I can also see the surefire report created a file with the following message 

org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found

The above message is generated from line "osgiContext.registerInjectActivateService" in a test class.

Avatar

Employee Advisor
Can you share an example github project where this problem occurs? It's easier to reproduce and help you. My second best guess is that you have a mix of OSGI and SCR annotations, but not the proper maven-plugins active to the generate the SCR metadata files.

Avatar

Correct answer by
Level 1
mvn clean package -DskipTests

 

Worked for me. If you use intelliJ or another IDE, make sure to invalidate its caches. An IDE behaves differently from Terminal, it has its own "environment" along with its own caching mechanisms.