I need to be able to switch off the 'Duplicate class' error and visual indicator (the red squiggly underline) that you get when you have two classes that are named the same in the same package but in different folders. In this case, 'main' and 'test'.
Background
It could be argued that this is a duplicate of this posting, however, I thought some background would be in order to avoid some of the obvious replies (and also, there is no satisfactory answer to that post).
This question is related to unit-testing and collaborator mocking. As everyone knows, Android violates the basic 'containment over inheritance' guideline for java development. This is why you need Robolectric to test lifecycle overrides without the framework crashing your tests. Your collaborator can't be mocked and injected in the normal way because the class under test is the collaborator.
In this case, my large corporate client has further violated the 'containment over inheritance' guideline by adding several layers of class extensions from Activitys and Fragments that have to be used instead. I can't modify these layers and attempting to mock out the internals is impractical. The simplest solution has been to create duplicates of the leaf classes of this extra layer that provide unit-test-friendly results to the class-under-test.
This works. When you run unit tests the test duplicate is resolved and when you run production code the production duplicate is resolved.
It's just that constant annoying error indication that needs to be suppressed.
Workarounds, IntelliJ plugins, custom class loaders, etc. - all will be considered (with instructions).
Aucun commentaire:
Enregistrer un commentaire