Creating Cucumber Test on Executable Docker Image

僤鯓⒐⒋嵵緔 提交于 2019-12-11 18:30:16

问题


I am trying to come up with an idea on how to create a Cucumber Test on Docker Executable Image?

public class GenerateNumber {
    public static void main(String[] args) {
        if (args != null && args.length > 0) {
            String input = args[0];

            if(input.equals("ODD")) {
                //GENERATE ODD NUMBERS FROM 0 TO 1000
            }else {
                //GENERATE EVEN NUMBERS FROM 0 TO 1000
            }
        }
    }
}

Supposed I have this simple class file...I am packaging it into an executable Jar File and use this class as an entry point in my application. The java file is deployed as a containerized image that will run my class.

Now, from a Cucumber Test perspective, how do I create a step definition file for such case?

This is a docker image right? I am coming up with a strategy on how to do this test. Any hints from someone who have done similar requirements?


回答1:


How you connect to your example depends on when you want to verify that it works.

My strategy would be to do it during build time of the application. This reduces Docker from the equation and any Java tutorial on Cucumber will be applicable. I have plenty of tutorials on my blog. Maybe this post can be of some help. Use modern versions of the tools.

If you want to connect to the application from a Cucumber step when the application runs in Docker, you need some way to do the connection. This is the same as connecting to any server application from the outside. An example could be to drive Selenium from Cucumber steps and and verify a web application. This post may be of help to understand how you can verify different types of applications. Again a bit dated, but the ideas have stayed the same.




回答2:


It is a little hard to understand what you are trying to achieve

If your docker image is a 'black box' that executes, and you need to analyse the result, you would have to build a separate cucumber test project that would execute on the host.

The cucumber step definitions methods could call methods that can start the docker image, log in to the container, pull files out, read logs etc, which can then be asserted against. You could use the Spotify docker client libraries to do that.



来源:https://stackoverflow.com/questions/49871059/creating-cucumber-test-on-executable-docker-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!