dongqianwei6664 2014-02-07 00:13
浏览 238
已采纳

Go测试中的单元测试之间是否可以有共享的上下文?

I am implementing a trie in Go as a way of learning the language. I want to write tests from the get go as a way of getting a feel for Go's approach to things.

One problem I am having when testing my trie is that I have to rebuild it for every unit test. Is there a way to reuse the same instantiation of my trie across unit tests? Ideally, I'd like a way to do this without any external dependencies.

  • 写回答

2条回答 默认 最新

  • dsa45132 2014-02-07 00:19
    关注

    Yes: Just construct it in func init() in your trie_test.go. (Or even use a literal.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突