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 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题