当前位置:网站首页>GoLand No Tests Were Run : 不能使用 fmt.Printf() <BUG>
GoLand No Tests Were Run : 不能使用 fmt.Printf() <BUG>
2022-06-30 05:04:00 【禪與計算機程序設計藝術】
問題描述:
I have a method that I am testing, and everything seems fine. However, when I run the tests in GoLand, I can see in the output that the tests "PASS" but the test runner says "no tests were run".
Here's the sample method in calculator.go
package calculator
import (
"fmt"
)
type Calculator struct {}
func New() Calculator {
return Calculator{}
}
func (s *Calculator) AddTwoNumbers(num_one, num_two int) int {
fmt.Printf("adding")
return num_one + num_two
}Here's the test in calculator_test.go:
package calculator
import (
"fmt"
"testing"
)
func Test_Calculator_AddTwoNumbers(t *testing.T) {
// Arrange
calculator := New()
// Act
total := calculator.AddTwoNumbers(1,2)
// Assert
if total != 3 {
msg := fmt.Sprintf("total should have been %d but instead was %d", 3, total)
t.Error(msg)
}
}問題解决:
Instead of fmt.Printf() in AddTwoNumbers try either fmt.Println() or fmt.Printf("foo\n')
The absence of the newline in the output of your AddTwoNumbers method is is causing the format of the test execution outputs to not have each test in a new line. The test runner is not being able to interpret that a test was run. Adding that newline, keeps a clean output.
https://stackoverflow.com/questions/68607771/goland-no-tests-were-run
边栏推荐
- Records of problems encountered in unity + hololens development
- 2021-07-29 compilation of Cura in ubantu18.04
- 图的一些表示方式、邻居和度的介绍
- Deep learning ----- different methods to realize inception-10
- LxC and LXD container summary
- Singapore parent-child tour, these popular attractions must be arranged
- PWN入门(2)栈溢出基础
- z-index属性在什么情况下会失效?
- Force buckle 349 Intersection of two arrays
- Free travel recommendation in Bangkok: introduction to the Mekong River in Bangkok
猜你喜欢

Unity3d lookat parameter description

Records of some problems encountered during unity development (continuously updated)

【VCS+Verdi聯合仿真】~ 以計數器為例

Harbor API 2.0 query

Universal Studios Singapore: a good place for a one-day parent-child tour in Singapore

PBR material: basic principle and simple fabrication

MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field

Create a simple battle game with photon pun

redis集群概念

UE4 method of embedding web pages
随机推荐
0 foundation starts self-study unit notes control direction becomes larger
Records of problems encountered in unity + hololens development
Pit of smoothstep node in shadergraph
On mask culling of unity
Network communication problem locating steps
Unity Logitech steering wheel access
ParticleSystem in the official Manual of unity_ Collision module
Generate a slice of mesh Foundation
What is multimodal interaction?
SCM learning notes: interrupt learning
Unity download and installation website
[recruitment] UE4 Development Engineer
Unity3d packaging and publishing APK process
Unity notes_ SQL Function
pycharm 数据库工具
Connect() and disconnect() of socket in C #
Unity + hololens2 performance test
LxC and LXD container summary
Nestjs配置静态资源,模板引擎以及Post示例
Spring Festival Tourism Strategy: welcome the new year in Bangkok, Thailand