英文:
Organizing and testing a go project
问题
我一直在使用Go语言开发一个多包项目:我的项目涉及多个包,每个包都用于实现不同的数据结构或算法 - https://github.com/arnauddri/algorithms
每个包都可以单独测试,并且运行良好。我可以在任何一个包中调用其他任何一个包。
目前我有几个问题:
-
是否有一种方法可以像Node.js那样将这些包“合并”在一起,将所有模块绑定到一个唯一的名称下?在这里,我希望添加一个
main.go
文件,定义一个名为“algo”的包,然后我可以使用任何底层包,比如algo.heap
、algo.queue
、algo.stack
... -
我的每个包都有测试,并且测试都正常工作。然而,每当我更改一个数据结构时,我都会检查使用该数据结构的其他包,以确保我的测试仍然通过,没有破坏任何东西。如何使
go test
命令从我的根文件开始运行所有的测试?
对于我的包布局的任何其他反馈都非常欢迎和赞赏
非常感谢!
英文:
I have been working on a multi-packages project in Go: my project involves several packages for each data structures or algorithms - https://github.com/arnauddri/algorithms
Each package can be tested separately and works fine. I can call any of the package in any other one.
At this stage I have several questions:
-
is there a way to 'unite' the packages like there is with node, binding all the module under a unique name? Here I would be looking to add a
main.go
file defining a package 'algo' and I could use any of the underlying packages withalgo.heap
,algo.queue
,algo.stack
... -
every one of my package has tests and they work fine, however everytime I change a data structure for example, I check in every other package using this one that my tests still pass and that I havent broken anything. How can I make
go test
work from my root file to launch all the tests?
Any other feedback on my package layout is more than welcome and appreciated
Many thanks
答案1
得分: 3
没有语言特性可以将包统一起来。
您可以在项目根目录下调用go test ./...
来运行所有测试。
英文:
There is no language feature that will unite packages.
You can call go test ./...
to run all of your tests from your project root.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论