Why can not add program argument to the junit configuration?

已回答

I have created a test and want to run my test. I use the latest version of IntelliJ with spring boot 2 and spring test starter.

I should be able to pas the program argument to the application. when I set up a JUnit run configuration the program arguments field is gray and disabled.

because of this, my test fails.

评论操作 固定链接

Hello,

The only supported scenario to create a configuration with an argument is from displayed parametrized test results run previously.

Here program parameters field is overused as one can’t pass parameters to the junit runner - only predefined parameters are allowed and I don’t think that it makes sense to allow editing of the field.

0
评论操作 固定链接

then how can I pass program argument which my application needs them?

0
评论操作 固定链接

If you want to pass parameters to the unit tests, consider using VM Options field, like -Dparam=value and in the test method you can read it with String value = System.getProperty("param");

0
评论操作 固定链接

When I debug the app deep down with running test, spring starts the main method of application which needs args which is empty while I have defined it in the run/debug configuration of the application.

0
评论操作 固定链接

JUnit tests are executed via the test runner framework, your main method is not called at all by JUnit, therefore you can't supply program arguments this way.

To pass the arguments to the application via its main method you have to use Application Run/Debug configuration type in IDEA.

0
评论操作 固定链接

I have already done this in the Application Run/Debug configuration   but problem pops up when I run JUnit test.

0
评论操作 固定链接

As I said, in case it is needed to pass an argument to program via JUnit test, please use VM Options

0
评论操作 固定链接

Thanks a lot for your kindly reply, I'm gonna use it in this way as you mentioned.

0

请先登录再写评论。