Expand my Community achievements bar.

SOLVED

wcm.io Junit testing getting error

Avatar

Level 2

Hi Guys,

I am trying to use wcm.io tool for Junit testing but its not working for me getting error:

java.lang.RuntimeException: Unable to invoke method 'bindInjector' for class org.apache.sling.models.impl.ModelAdapterFactory

I have used this code:

@RunWith(MockitoJUnitRunner.class)

public class MyDictionaryTest {

  @Rule

   public final AemContext context = new AemContext();

 

  @BeforeClass

  public static void beforeClass(){

  System.out.println("Before Class");

  }

@Before

  public void before(){

  System.out.println("Before Test Case");

  }

@Test

  public void isGreaterTest(){

  System.out.println("Test");

  MyDictionary helloWorld = new MyDictionary();

  assertTrue("Num 1 is greater than Num 2" , helloWorld.isGreater(5, 3));

}

@After

public void after(){

  System.out.println("After Test Case");

}

public void afterClass(){

  System.out.println("After Class");

}

}

Kindly help me to resolve it

Thanks

meenal

1 Accepted Solution

Avatar

Correct answer by
Employee
2 Replies

Avatar

Correct answer by
Employee

Have a look at the core-components, we have unit-tests are in there: GitHub - Adobe-Marketing-Cloud/aem-core-wcm-components: AEM Core WCM Components