arquillian / arquillian-cube

Control (docker, kubernetes, openshift) containers in your tests with ease!
http://arquillian.org/arquillian-cube/
121 stars 98 forks source link

TestNG Container lifecycle #972

Open aahmed-se opened 6 years ago

aahmed-se commented 6 years ago

I am trying add to some container management in arquillian testng extended class. From what I see the container is not materialized till the BeforeTest annotated phase . But that means I can't use the common setup routine with @BeforeTest. Is there a way to override this behavior ?

    @DockerContainer
    Container pingpong = Container.withContainerName("pingpong")
        .fromImage("jonmorehouse/ping-pong")
        .withPortBinding(8080)
        .build();

    @BeforeSuite
    public void beforeSuite() throws IOException {
        //LOG.info(pingpong.getIpAddress());
        LOG.info("Before Suite");
    }

    @BeforeClass
    public void beforeClass() throws IOException {
        //LOG.info(pingpong.getIpAddress());
        LOG.info("Before Class");
    }

    @BeforeTest
    public void beforeTest() throws IOException {
        //LOG.info(pingpong.getIpAddress());
        LOG.info("Before Test");
    }

    @BeforeMethod
    public void beforeMethod() throws IOException {
        LOG.info("Before Method");
        LOG.info(pingpong.getIpAddress());
lordofthejars commented 6 years ago

Yes, the container is materialized at testenricher phase which is before test phase. I am not aware how exactly this works with Test NG, but as I said the container is materialized at test enricher phase.

lordofthejars commented 6 years ago

Look can you try to put a debug point at https://github.com/arquillian/arquillian-cube/blob/master/docker/docker/src/main/java/org/arquillian/cube/docker/impl/client/containerobject/CubeContainerObjectTestEnricher.java#L103 and see exactly in which phase is run in Test NG?