当前位置:网站首页>Golan no tests were run: fmt Printf() < BUG>
Golan no tests were run: fmt Printf() < BUG>
2022-06-30 05:05:00 【Zen and the art of computer programming】
Problem description :
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)
}
}Problem solving :
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
边栏推荐
猜你喜欢

Writing unityshader with sublimetext

Force buckle 209 Minimum length subarray

Some problems encountered in unity steamvr

力扣589:N 叉树的前序遍历

Solution to Autowired annotation warning

Some books you should not miss when you are new to the workplace

Detailed explanation of the process of "flyingbird" small game (camera adjustment and following part)

Force buckle 59 Spiral matrix II

PS1 Contemporary Art Center, Museum of modern art, New York

The golden deer, a scenic spot in London -- a sailing museum that tells vivid sailing stories
随机推荐
Postman 做测试的 6 个常见问题
Harbor API 2.0 query
Unity script life cycle and execution sequence
Chapter 10 of OpenGL super classic (7th Edition) calculation shader
C # Foundation
Unity lens making
Force buckle 209 Minimum length subarray
[vcs+verdi joint simulation] ~ take the counter as an example
力扣2049:统计最高分的节点数目
Autowired注解警告的解决办法
力扣27. 移除元素
Solution to 293 problems in the week of Li Kou
Yolov5 torch installation
一条命令运行rancher
LxC and LXD container summary
Force buckle 704 Binary search
Recommended cultural landmarks of these tourist attractions in Bangkok
Force buckle 59 Spiral matrix II
Ripple effect of mouse click (unity & shader)
003-JS-DOM-Attr-innerText