This is a creation in Article, where the information may have evolved or changed.
Go Test Command parameter issues
When using go test to unit test the Go code, encountered the issue of command parameters, Google, did not find a good explanation, in fact, is a few details.
The problem is that I want to enter some command-line arguments to run the program when I do the unit test.
Refer to the Go official documentation, just add-args and parameters to go test
For example
Go Test-args-classpath E:\testcase HelloWorld
That's the top.
-classpath E:\testcase HelloWorld
Is the parameter I entered, but this error:
Flag provided but not Defined:-classpath
It means that go test interprets-classpath as its own argument, rather than taking all the strings behind-args as a parameter of my program input.
There is no way, I had to in the program bar-classpath changed to Classpath, so the command line as follows
Go Test-args classpath E:\testcase HelloWorld
This barely solves the problem, but the reason for go test changed my source program.
In addition, when I want to print debug information, that is, to go test to increase the-V parameter, also encountered a small problem, I entered the
Go test-v-args classpath E:\testcase HelloWorld
In the source code this, I pass the os. Args goes to get command-line arguments, but-V is treated as an input to my command line, not ignored. In principle, it should be-args to be treated as a command-line argument, and the go test does not actually do this. So I can only modify the source program to complete the test.
In the go test process, the use of command line parameters is relatively small, but I have encountered, and there are some unexpected problems, the go test is not perfect. In addition, I was just beginning to touch the go language, perhaps there is a better way or understand the wrong, here just to make a note for yourself, please forgive me.