Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class MyTests extends BaseContextSensitiveTest {
  public void getPatientByName_shouldReturnValidPatients()
  {
      List patients = Context.getPatientService().getPatientsByName("bob"); Assert.assertEquals(34, patients.get(0).getPatientId());
  }
}

...

  • How can I authenticate to the Context without putting my username and password in the unit test code?
    Use the authenticate() method found in BaseContextSensitiveTest
  • That authenticate method is awesome...but I want to authenticate without user intervention. How can I do that easily?
    Define two properties in your runtime properties file: junit.username and junit.password.
  • Why am I getting the error org.openmrs.api.APIException: Service not found: interface org.openmrs.api ..... in my unit test?
    You're trying to use a basic unit test to do Context/API testing. Extend the org.openmrs.test.BaseContextSensitiveTest class.
  • Why am I getting the error: Already value [] for key [] bound to thread [main]?
    Your web unit test is probably extending BaseContextSensitiveTest intead of BaseWebContextSensitiveTest
  • Why am I getting the error: org.openmrs.api.APIException: contextDAO is null . . . in my unit test?
    Spring was not properly set up for OpenMRS. Try running a maven install on your local copy of OpenMRS (In Eclipse click run as, then select maven install).