英文:
Why runtime.caller(0) is giving different path with '--cover' argument in unit testing
问题
当尝试执行一个没有任何参数的单元测试函数时,它会给出以下输出路径:
C:/Program Files (x86)/Go1.8\bin\go.exe" test -v gclassec/skyline/loggers -run ^TestCreateLogFilesPath$
文件路径:=== C:/GerritNew/goclassec/src/gclassec/skyline/loggers/logs.go
但是当我尝试使用任何参数,比如 --cover
,文件路径的值会改变如下:
"C:/Program Files (x86)/Go1.8\bin\go.exe" test -v --cover gclassec/skyline/loggers -run ^TestCreateLogFilesPath$
文件路径:=== gclassec/skyline/loggers/_test/_obj_test/logs.go
我正在使用 runtime.caller(0)
来获取文件路径。
英文:
When trying to execute a unit test function without any argument it give following output path
C:/Program Files (x86)/Go1.8\bin\go.exe" test -v gclassec/skyline/loggers -run ^TestCreateLogFilesPath$
filePath:=== C:/GerritNew/goclassec/src/gclassec/skyline/loggers/logs.go
But when I try to run it with any argument such as --cover
the file path value changes as below:
"C:/Program Files (x86)/Go1.8\bin\go.exe" test -v --cover gclassec/skyline/loggers -run ^TestCreateLogFilesPath$
filePath:=== gclassec/skyline/loggers/_test/_obj_test/logs.go
I am using runtime.caller(0)
to get file path.
答案1
得分: 0
通过使用os.Getwd()和runtime.caller,并使用一个变量来区分测试和正常运行,它可以工作。
英文:
It worked by using os.Getwd() and runtime.caller with a variable to diffrentiate between testing and normal running.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论