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:
@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 You can see some examples here and this small module can help you write some test data.
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…
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
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.