doutang7661 2017-09-13 20:00
浏览 52
已采纳

如何在操场上使用测试包?

The testing package is available in the go playground.

How can I use the go playground to demonstrate testing concepts, without access to go test?

My assumption is it's possible using the testing.RunTests function. My attempts to do so always generate only "testing: warning: no tests to run".

Example: https://play.golang.org/p/PvRCMdeXhX

For context, my use case is for sharing quick examples of tests, examples and benchmarks with colleagues. I rely on go playground for sharing code snippets like this often.

  • 写回答

2条回答 默认 最新

  • doubu5154 2017-09-13 20:13
    关注

    You need to use testing.Main:

    func main() {
        testSuite := []testing.InternalTest{
            {
                Name: "TestCaseA",
                F:    TestCaseA,
            },
        }
        testing.Main(matchString, testSuite, nil, nil)
    }
    

    https://play.golang.org/p/DQsIGKNWwd

    If you want to use the "non deprecated", but unstable way:

    https://play.golang.org/p/4zH7DiDcAP

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

报告相同问题?

悬赏问题

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