简体   繁体   中英

How disable @DependsOn annotation in arquillian tests?

I try to test singleton that have annotation @DependsOn where i mark another singletons that must be initialized before. But in test i don't want to load them, because its a lot of useless classes for my test. For ex:

@Singleton
@DependsOn({"anotherSingleton1", "anotherSingleton2"...})
public class SomeSingleton {
... methods and logic...
}

Here's example of test:

public class SomeSingletonIT extends Arquillian {

    @Mock SomeClassInSingleton;
    ... another mocks...

    @Inject
    @InjectMocks
    SomeSingleton instance;

    @BeforeClass
    public void initMocks() {
        mocks logic
    }



    @Deployment
    public static WebArchive createDeployment() {

        return ShrinkWrap.create(WebArchive.class, "test.war")
                .addClasses(
                        SomeSingleton.class
                        )
                .addAsLibraries(some Libs)
                .addAsWebInfResource(EmptyAsset.INSTANCE,"beans.xml");
    }

    @Test
    public void testGetProactiveSubjects() throws Exception {
        System.out.println("***----------------------------------***");
        assertNotNull(instance);
        ...some assertions...
        System.out.println("***----------------------------------***");
    }

}

I got exception that arquillian doesn't see classes of singletons in annotation @DependsOn. But if i include them in test archive - i will have to include all theirs dependencies too. And mock some logic in them that inits in @PostConstruct's. So... How can I disable or mock @DependsOn? I use arquillian with wildfly managed container.

One idea which comes to my mind would be to implement a test double - dummy object - which you would substitute in your test deployment rather than deploying real singletons. This would save you from adding tons of dependencies and execution overhead when deploying your archive under test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM