I can not get the usercontext

I used the junit test and but I cant get the usercontext.How to fix it

try replacing s.getService with Context.getUserService();

I did as you said Context s= (Context) applicationContext.getBean(“context”); s.getUserService().getUserByUsernameOrEmail(“sd”); but the same problem occurs

i was meaning some thing like UserService userService = Context.getUserService();

It does not work :sob:

what happens on writing it the same way as i wrote it above

you mean you write as the same way but the bug didn’t occur?

@dkayiwa Hello expert ,I can not get the userContext by the way shown as the illustration

If you need to test something using the UserService fetched from the Context, your test class should extend org.openmrs.test.BaseModuleContextSensitiveTest or org.openmrs.test.jupiter.BaseModuleContextSensitiveTest if you only need to test against openmrs-core 2.4 or newer. Then, inside your test class you can just do:

UserService userService = Context.getUserService();

Which is what @herbert24 was trying to direct you towards.

1 Like