Report Development - Testing Output within IDE

I am in the process of developing an indicator report but I am interested in running the report against a known database to validate the output. Is there a faster way of doing this rather than:

  1. Compiling module

  2. Deploying to running OpenMRS server

  3. Running report

@mseaton @rubailly any advice

@ssmusoke -unit tests can help you here. If you want to connect to an existing database, you’ll have to set useInMemoryDatabase() to return false …check example here …though writing tests that you can ship with your code would be better :slight_smile: You can see some examples here and this small module can help you write some test data.

In addition to the above, as documented here: https://wiki.openmrs.org/display/docs/Unit+Tests You can use this class to connect to your real database to generate a test dataset: https://github.com/openmrs/openmrs-core/blob/master/api/src/test/java/org/openmrs/test/CreateInitialDataSet.java

@ssmusoke in the past I have done this using the TestDataManager class, like this: https://github.com/PIH/openmrs-module-mirebalaisreports/blob/master/api/src/test/java/org/openmrs/module/mirebalaisreports/library/EncounterDataLibraryTest.java#L71

I am bringing this back up - is there a way of running a report against a database so that I can dump the output into the console to help me tweak the report build process?

@ssmusoke, yes. Did the above suggestions not work? I do this all the time - if there are specific issues you are hitting, we can try to resolve them. Maybe best done over a chat channel…

@mseaton I have this TestCase for one of our reports pointing to the server https://github.com/METS-Programme/openmrs-module-ugandaemr-reports/pull/170 on needing to setUserContext()

org.openmrs.api.APIException: A user context must first be passed to setUserContext()...use Context.openSession() (and closeSession() to prevent memory leaks!) before using the API
    at org.openmrs.api.context.Context.getUserContext(Context.java:236)
    at org.openmrs.api.context.Context.getAuthenticatedUser(Context.java:595)
    at org.openmrs.module.reporting.evaluation.EvaluationContext.<init>(EvaluationContext.java:111)
    at org.openmrs.module.reporting.evaluation.EvaluationContext.<init>(EvaluationContext.java:96)
    at org.openmrs.module.ugandaemrreports.reports.TestSetup106A1AReport.test106AExport(TestSetup106A1AReport.java:24)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Results :

Tests in error: test106AExport(org.openmrs.module.ugandaemrreports.reports.TestSetup106A1AReport): A user context must first be passed to setUserContext()…use Context.openSession() (and closeSession() to prevent memory leaks!) before using the API

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

Well, the first and biggest issue is that this does not extend BaseModuleContextSensitiveTest. Please have a look at some of the actual examples that were posted above.

Thanks I think it was fatigue, I will go over it again when I have a fresh brain next week