Golang test编译使用

2024-09-08 13:38
文章标签 编译 golang 使用 test

本文主要是介绍Golang test编译使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

创建文件my_test.go

package testsimport "testing"func TestMy(t *testing.T) {t.Log("TestMy")
}

通常用法:

$ go test -v -run TestMy my_test.go
=== RUN   TestMyTestMy: my_test.go:6: TestMy
--- PASS: TestMy (0.00s)
PASS
ok      command-line-arguments  0.619s

编译测试文件

go test -c my_test.go -o my.test

如果不用-o则会生成tests.test文件

编译后使用

$ ./my.test -test.v -test.run TestMy
=== RUN   TestMyTestMy: my_test.go:6: TestMy
--- PASS: TestMy (0.00s)
PASS

测试命令参数:


-test.bench regexprun only benchmarks matching regexp
-test.benchmemprint memory allocations for benchmarks
-test.benchtime drun each benchmark for duration d (default 1s)
-test.blockprofile filewrite a goroutine blocking profile to file
-test.blockprofilerate rateset blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
-test.count nrun tests and benchmarks n times (default 1)
-test.coverprofile filewrite a coverage profile to file
-test.cpu listcomma-separated list of cpu counts to run each test with
-test.cpuprofile filewrite a cpu profile to file
-test.failfastdo not start new tests after the first test failure
-test.list regexplist tests, examples, and benchmarks matching regexp then exit
-test.memprofile filewrite an allocation profile to file
-test.memprofilerate rateset memory allocation profiling rate (see runtime.MemProfileRate)
-test.mutexprofile stringwrite a mutex contention profile to the named file after execution
-test.mutexprofilefraction intif >= 0, calls runtime.SetMutexProfileFraction() (default 1)
-test.outputdir dirwrite profiles to dir
-test.parallel nrun at most n tests in parallel (default 12)
-test.run regexprun only tests and examples matching regexp
-test.shortrun smaller test suite to save time
-test.testlogfile filewrite test action log to file (for use only by cmd/go)
-test.timeout dpanic test binary after duration d (default 0, timeout disabled)
-test.trace filewrite an execution trace to file
-test.vverbose: print additional output

这篇关于Golang test编译使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1148258

相关文章

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

Spring AI使用tool Calling和MCP的示例详解

《SpringAI使用toolCalling和MCP的示例详解》SpringAI1.0.0.M6引入ToolCalling与MCP协议,提升AI与工具交互的扩展性与标准化,支持信息检索、行动执行等... 目录深入探索 Spring AI聊天接口示例Function CallingMCPSTDIOSSE结束语

Linux系统之lvcreate命令使用解读

《Linux系统之lvcreate命令使用解读》lvcreate是LVM中创建逻辑卷的核心命令,支持线性、条带化、RAID、镜像、快照、瘦池和缓存池等多种类型,实现灵活存储资源管理,需注意空间分配、R... 目录lvcreate命令详解一、命令概述二、语法格式三、核心功能四、选项详解五、使用示例1. 创建逻

在Java中使用OpenCV实践

《在Java中使用OpenCV实践》用户分享了在Java项目中集成OpenCV4.10.0的实践经验,涵盖库简介、Windows安装、依赖配置及灰度图测试,强调其在图像处理领域的多功能性,并计划后续探... 目录前言一 、OpenCV1.简介2.下载与安装3.目录说明二、在Java项目中使用三 、测试1.测

C++中detach的作用、使用场景及注意事项

《C++中detach的作用、使用场景及注意事项》关于C++中的detach,它主要涉及多线程编程中的线程管理,理解detach的作用、使用场景以及注意事项,对于写出高效、安全的多线程程序至关重要,下... 目录一、什么是join()?它的作用是什么?类比一下:二、join()的作用总结三、join()怎么

mybatis中resultMap的association及collectio的使用详解

《mybatis中resultMap的association及collectio的使用详解》MyBatis的resultMap定义数据库结果到Java对象的映射规则,包含id、type等属性,子元素需... 目录1.reusltmap的说明2.association的使用3.collection的使用4.总

Go语言编译环境设置教程

《Go语言编译环境设置教程》Go语言支持高并发(goroutine)、自动垃圾回收,编译为跨平台二进制文件,云原生兼容且社区活跃,开发便捷,内置测试与vet工具辅助检测错误,依赖模块化管理,提升开发效... 目录Go语言优势下载 Go  配置编译环境配置 GOPROXYIDE 设置(VS Code)一些基本

Spring Boot配置和使用两个数据源的实现步骤

《SpringBoot配置和使用两个数据源的实现步骤》本文详解SpringBoot配置双数据源方法,包含配置文件设置、Bean创建、事务管理器配置及@Qualifier注解使用,强调主数据源标记、代... 目录Spring Boot配置和使用两个数据源技术背景实现步骤1. 配置数据源信息2. 创建数据源Be

Java中使用 @Builder 注解的简单示例

《Java中使用@Builder注解的简单示例》@Builder简化构建但存在复杂性,需配合其他注解,导致可变性、抽象类型处理难题,链式编程非最佳实践,适合长期对象,避免与@Data混用,改用@G... 目录一、案例二、不足之处大多数同学使用 @Builder 无非就是为了链式编程,然而 @Builder

在MySQL中实现冷热数据分离的方法及使用场景底层原理解析

《在MySQL中实现冷热数据分离的方法及使用场景底层原理解析》MySQL冷热数据分离通过分表/分区策略、数据归档和索引优化,将频繁访问的热数据与冷数据分开存储,提升查询效率并降低存储成本,适用于高并发... 目录实现冷热数据分离1. 分表策略2. 使用分区表3. 数据归档与迁移在mysql中实现冷热数据分