如何确定在测试用例期间导入的文件树?
How to determine the tree of files which are imported during a test case?
当我 运行 在 Go 中进行测试时,有什么方法可以直接或间接地获取代码导入的文件列表?例如,这可以帮助我在调试失败的测试时排除代码库某些部分的更改。
或者,使用 Git,我们能否找出给定测试中执行的文件的最低共同祖先 git 树节点?
上下文:我正在研究我的测试套件的自动易碎检测,我希望能够了解每个测试的依赖树,以便我可以更好地检测易碎测试。
例如,如果 TestX
的代码版本 x
失败,并且稍后更改了同一代码库中根本不被 TestX
使用的某些文件,然后 TestX
通过,我希望能够检测到这是一个不稳定的测试,即使测试套件 运行 所在的整体代码库已经更改。
您可能正在寻找 go list -test -deps [packages]
。
有关标志作用的解释,您可以查看 Go 命令 List packages or modules:
-deps
:
The -deps
flag causes list to iterate over not just the named packages but also all their dependencies. It visits them in a depth-first post-order traversal, so that a package is listed only after all its dependencies. [...]
-test
:
The -test
flag causes list
to report not only the named packages but also their test binaries (for packages with tests), to convey to source code analysis tools exactly how test binaries are constructed. The reported import path for a test binary is the import path of the package followed by a ".test" suffix, as in "math/rand.test". [...]
也许我会说的很明显,但请记住 list
适用于包,而不是单个文件,所以上面的命令将包括非测试源的依赖项(无论如何这应该是你想要的).
当我 运行 在 Go 中进行测试时,有什么方法可以直接或间接地获取代码导入的文件列表?例如,这可以帮助我在调试失败的测试时排除代码库某些部分的更改。
或者,使用 Git,我们能否找出给定测试中执行的文件的最低共同祖先 git 树节点?
上下文:我正在研究我的测试套件的自动易碎检测,我希望能够了解每个测试的依赖树,以便我可以更好地检测易碎测试。
例如,如果 TestX
的代码版本 x
失败,并且稍后更改了同一代码库中根本不被 TestX
使用的某些文件,然后 TestX
通过,我希望能够检测到这是一个不稳定的测试,即使测试套件 运行 所在的整体代码库已经更改。
您可能正在寻找 go list -test -deps [packages]
。
有关标志作用的解释,您可以查看 Go 命令 List packages or modules:
-deps
:
The
-deps
flag causes list to iterate over not just the named packages but also all their dependencies. It visits them in a depth-first post-order traversal, so that a package is listed only after all its dependencies. [...]
-test
:
The
-test
flag causeslist
to report not only the named packages but also their test binaries (for packages with tests), to convey to source code analysis tools exactly how test binaries are constructed. The reported import path for a test binary is the import path of the package followed by a ".test" suffix, as in "math/rand.test". [...]
也许我会说的很明显,但请记住 list
适用于包,而不是单个文件,所以上面的命令将包括非测试源的依赖项(无论如何这应该是你想要的).