当前位置:网站首页>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
边栏推荐
- Create a simple battle game with photon pun
- 003-JS-DOM-Attr-innerText
- 力扣27. 移除元素
- Approaching history, introduction to the London Guard Museum
- Output directory of log files after unity3d packaging
- Unity3d realizes Google Digital Earth
- Using the command line to convert JSON to dart file in fluent
- Unity supports the platform # define instruction of script
- 【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example
- Pit of smoothstep node in shadergraph
猜你喜欢

深度学习------不同方法实现Inception-10

How does unity use mapbox to implement real maps in games?

pycharm 数据库工具

Unreal 4 unavigationsystemv1 compilation error

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

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

Procedural animation -- inverse kinematics of tentacles

On mask culling of unity

Force buckle 209 Minimum length subarray

中文版PyCharm改为英文版PyCharm
随机推荐
力扣589:N 叉树的前序遍历
Pytorchcnn image recognition and classification model training framework
Nestjs中控制器和路由的配置使用
Winter vacation parent-child tour, these new york attractions are not only fun but also knowledge
Some books you should not miss when you are new to the workplace
Sailing experience not to be missed in New York Tourism: take you to enjoy the magnificent city scenery from different perspectives
Have a heart beating Valentine's day in Singapore
Unity packaging failure solution
A virtual reality secret room escape adventure, let you see Technology Singapore
Thread safety and processing caused by multithreading
力扣977. 有序数组的平方
Singleton mode in unity
力扣27. 移除元素
Initial environment configuration of the list of OpenGL super classic (version 7) vs2019
Win10 vs2015 compiling curaengine
Force buckle 209 Minimum length subarray
Introduction to some representations, neighbors and degrees of Graphs
Unity lens making
Harbor API 2.0 query
Oracle-数据的基本操作