组织和测试一个Go项目

huangapple go评论76阅读模式
英文:

Organizing and testing a go project

问题

我一直在使用Go语言开发一个多包项目:我的项目涉及多个包,每个包都用于实现不同的数据结构或算法 - https://github.com/arnauddri/algorithms

每个包都可以单独测试,并且运行良好。我可以在任何一个包中调用其他任何一个包。

目前我有几个问题:

  • 是否有一种方法可以像Node.js那样将这些包“合并”在一起,将所有模块绑定到一个唯一的名称下?在这里,我希望添加一个main.go文件,定义一个名为“algo”的包,然后我可以使用任何底层包,比如algo.heapalgo.queuealgo.stack...

  • 我的每个包都有测试,并且测试都正常工作。然而,每当我更改一个数据结构时,我都会检查使用该数据结构的其他包,以确保我的测试仍然通过,没有破坏任何东西。如何使go test命令从我的根文件开始运行所有的测试?

对于我的包布局的任何其他反馈都非常欢迎和赞赏 组织和测试一个Go项目

非常感谢!

英文:

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 with algo.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 组织和测试一个Go项目

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.

huangapple
  • 本文由 发表于 2015年1月31日 01:39:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/28241595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定