mardi 15 octobre 2019

Can I remove @Import statement inherited from super class?

I'm writing some tests for my app and most of them uses the same @TestConfiguration that I'm providing by @Import(TestConfig.class). Import statement is used only in main abstract superclass. Other classes extends it. However, for some of my tests I need to provide other @TestConfiguration and the same body as superclass. Is there any way how to do it?

I've been trying to make a common abstract test class with body and then another abstract class that inherits it and adds Import statement. However, I feel that there may be a better way.

@Import(TestConfig.class)
abstract class AbstractTest { /* body */}

class TestWithConfig extends AbstractTest { /* it's ok */ }

class TestWithoutConfig extends AbstractTest { 

/* i want here only to use the AbstractTest body but don't use imported test configuration by inheritance.*/

eg. @TestConfiguration
static class newConfig { ... } 

}

Is there any way to do this? Thanks.

Aucun commentaire:

Enregistrer un commentaire