unit vs integration test naming conventions and @should

Hi there!

I see that lots of modules and also tests in core that need the application context and a DB are simply called like ClassNameTest.java which does not differentiate them from unit tests (which do not need app context and DB).

Furthermore there are some classes that are called like

What should a dev do? What would be desired by the community? Name classes which need app context (are ConcextSensitive) ClassNameIT.java ?

Also tests are annotated with @should. Is my assumption right that these descriptions can be used for unit and integration tests and thus can end up splitted into ClassNameTest.java and ClassNameIT.java ? Since for example if I just test that a method throws an exception given null I would want this in a unit test and to test that the method returns a list of objects from the DB I probably want this as an integration test.

1 Like

Originally, we didn’t differentiate tests between unit and integration/component tests so we appended Test to all of them.

There’s a benefit in putting unit tests in a separate class as they are much faster, which allows a dev to rerun them more often.

In openmrs-core we now have 2 separate profiles: “integration-test” for tests ending with *IT.java (ContextSensitive) “performance-test” for tests ending with *PT.java

We do not plan to fix existing tests to follow that convention, however, we’d like to create new tests that way. Since you mention it, it’s a sign it’s not documented well enough.

By the end of this week I’ll update https://wiki.openmrs.org/display/docs/Testing and subpages and I’ll kindly ask you for a follow up review.

Your assumption about @should is right, though the OpenMRS Test plugin for Eclipse doesn’t support that. I’m not sure if anyone is still using that plugin anyway.

1 Like

Thanks a lot @raff!

now that explains it :slight_smile:

will do!

The correct thing should actually be that unit tests should not be Context sensitive and should typlically be using mock objects but I know we never got this right.

@should annotation is intended to be metadata that is used by the behavior test generator plugin.

Is there/should there be a “cleanup” issue to rename current context sensitive test classes to “ClassNameIT.java” instead of “ClassNameTest.java” ?

When PIH and ThoughtWorks were working on the Mirebalais project, we decided to use XyzTest for unit tests, XyzComponentTest for “normal” context-sensitive tests (that should still be run on the dev’s machine), and XyzIntegrationTest (only run on CI).

I still think that makes sense (particular, that we don’t want to offload all context-sensitive tests to only run in CI).