GoLand No Tests Were Run : 不能使用 fmt.Printf() <BUG;

Posted 禅与计算机程序设计艺术

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GoLand No Tests Were Run : 不能使用 fmt.Printf() <BUG;相关的知识,希望对你有一定的参考价值。

问题描述:

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

以上是关于GoLand No Tests Were Run : 不能使用 fmt.Printf() <BUG;的主要内容,如果未能解决你的问题,请参考以下文章

在pycharm中调用 unittest,然后显示 no tests were found是啥原因?

A query was run and no Result Maps were found for the Mapped Statement....

A query was run and no Result Maps were found for the Mapped Statement

A query was run and no Result Maps were found for the Mapped Statement

出错:Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were foun

MyBatis报错:A query was run and no Result Maps were found for the Mapped Statement