当前位置:网站首页>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
边栏推荐
- harbor api 2.0查询
- Unity3d Google Earth
- Approaching history, introduction to the London Guard Museum
- Singapore parent-child tour, these popular attractions must be arranged
- [vcs+verdi joint simulation] ~ take the counter as an example
- Webots notes day 2
- 0 basic unity course. Bricklaying
- Unity enables simple music visualization
- Important knowledge points in unity3d
- A collection of errors encountered in machine learning with unity
猜你喜欢

Unity lens making

Meet in Bangkok for a romantic trip on Valentine's Day

SCM learning notes: interrupt learning

Introduction to some representations, neighbors and degrees of Graphs

Writing unityshader with sublimetext

MinGW-w64下载文件失败the file has been downloaded incorrectly!

Singapore parent-child tour, these popular attractions must be arranged
Sourcetree usage

Unity/ue reads OPC UA and OPC Da data (UE4)

Pit of smoothstep node in shadergraph
随机推荐
0 foundation starts self-study unit notes control direction becomes larger
LXC 和 LXD 容器总结
Deeply understand the function calling process of C language
Photon pun refresh hall room list
Sourcetree usage
JPA复合主键使用
Easyrecovery data recovery software recovers my photo and video data two years ago
Error about the new version of UE4: unavigationsystemv1:: simplemovetoactor has been deprecated
MinGW-w64下载文件失败the file has been downloaded incorrectly!
SCM learning notes: interrupt learning
力扣209. 长度最小的子数组
Unity multiple UI page turning left and right
PS1 Contemporary Art Center, Museum of modern art, New York
Chapter 10 of OpenGL super classic (7th Edition) calculation shader
Brew install NVM command not found solution
Create transfer generation point
图的一些表示方式、邻居和度的介绍
Spring Festival Tourism Strategy: welcome the new year in Bangkok, Thailand
Thread safety and processing caused by multithreading
PBR material: basic principle and simple fabrication