当前位置:网站首页>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
边栏推荐
- Exploration of unity webgl
- Procedural animation -- inverse kinematics of tentacles
- Basic operations of Oracle data
- Four methods of unity ugui button binding events
- C # equipment synthesis
- Generate a slice of mesh Foundation
- JPA composite primary key usage
- On mask culling of unity
- 力扣349. 两个数组的交集
- The difference between SVG and canvas
猜你喜欢
Unity/ue reads OPC UA and OPC Da data (UE4)
A collection of errors encountered in machine learning with unity
Unity2019.3.8f1 development environment configuration of hololens2
Writing unityshader with sublimetext
Pycharm database tool
QT connecting external libraries
Check London attractions suitable for parents and children in winter vacation
Force buckle 977 Square of ordered array
Unity automatic pathfinding
Exploration of unity webgl
随机推荐
Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
力扣977. 有序数组的平方
Unreal 4 learning notes - Animated Montage
Unity lens making
Unity profiler performance analysis
On mask culling of unity
svg和canvas的区别
One command to run rancher
Exploration of unity webgl
Marvel fan welfare: Singapore Madame Tussauds Wax Museum Marvel 4D experience Museum
Win10 vs2015 compiling curaengine
Nestjs配置静态资源,模板引擎以及Post示例
Detailed explanation of sorting sort method of JS array
Generate a slice of mesh Foundation
Records of problems encountered in unity + hololens development
力扣2049:统计最高分的节点数目
2021-07-29 compilation of Cura in ubantu18.04
C # Foundation
Autowired注解警告的解决办法
How does unity use mapbox to implement real maps in games?