简体   繁体   English

使用 testify 的套件 package 时 go 中可能未使用的参数

[英]Potentially unused parameter in go when using testify's suite package

I want to execute subtests using the testify/suite package .我想使用 testify testify/suite package执行子测试。

I am declaring my Unit suite as follows我声明我的单元套件如下


type UnitSuite struct {
    suite.Suite
}

func TestUnitSuite(t *testing.T) {
    suite.Run(t, &UnitSuite{})
}

and here is my subtest这是我的子测试

func (us *UnitSuite) ΤestSomething() {
    for i := range testVars {
        i := i
        us.T().Run(testVars[i].name, func(t *testing.T) {
        ...

Ι am getting the following linting warning for func(t *testing.T)我收到以下关于func(t *testing.T)的 linting 警告

potentially unused parameter: 't'unusedparams

When trying to substitute with the testing suite's function T() that is supposes to retrieve the testing context当尝试用测试套件的 function T()替换时,它应该检索testing上下文

us.T().Run(testVars[i].name, func(us.T()) {

I get this error in func(us.T()) <-- errors out我在func(us.T()) <--错误中得到这个错误

missing ',' in parameter listsyntax

What is the way to go about this that does not produce neither errors nor linting warnings? go 的方法是什么,既不会产生错误也不会产生 linting 警告?

If you want to declare an unused parameter (usually to satisfy an interface or other requirements), you can name it a single underscore.如果要声明未使用的参数(通常是为了满足接口或其他要求),可以将其命名为单个下划线。 For example:例如:

Run(name, func(_ *testing.T) {})

Note that you cannot put a value in function declaration, so func(us.T()) { is always wrong.请注意,您不能在 function 声明中输入,因此func(us.T()) {总是错误的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Go 测试中使用带有 testify/suite 的自定义标志 - How to use custom flag with testify/suite in Go test 使用 testify 检查 go 结构中字段的动态值 - Check dynamic value for field in struct in go using testify 运行 http.ListenAndServe() On Tests using stretchr/testify suite Stop Test From Proceed - Run http.ListenAndServe() On Tests using stretchr/testify suite Stop Test From Proceed 错误`您正在测试的代码需要在 testify 包中进行 1 次调用` - Error `The code you are testing needs to make 1 more call(s)` in testify package 谁正在使用我的Go包 - who's using my Go package 作证,当期望已经写好时模拟意外的方法调用,但是方法被调用了两次,参数不同 - Testify, mock unexpected method call when the expectation is already written , but the method is called twice with different parameter 尝试与 golang testify/suite 并行运行测试失败 - Trying to run tests in parallel with golang testify/suite fails 使用 MUX 包将查询参数传递给 Go HTTP 请求处理程序 - Passing a query parameter to the Go HTTP request handler using the MUX package 如何使用go的net / http包提供php文件? - How to serve php files using go's net/http package? 使用 testify 模拟 grpc 客户端请求和响应 - mock grpc client request and response using testify
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM