案例

Golang 测试框架

cal.go

package test

func add(a,b int) int{
	return a + b
}

cal_test.go

package test

import (
	"fmt"
	//引入go的测试框架
	"testing"
)
//测试框架的函数必须以TestXxx形式
func TestAdd(t *testing.T) {
	res := add(10, 2)
	if res == 2 {
		fmt.Println("错误")
	} else {
		t.Log("正确")
	}
}

测试套件要与被测试的包在同一个包下,文件名必须以_test.go结尾,方法必须以TestXxx(*testing.T)的形式

相关文章:

  • 2022-12-23
  • 2021-11-23
  • 2021-09-28
  • 2021-11-30
  • 2021-08-20
  • 2021-10-12
  • 2022-01-23
  • 2021-12-06
猜你喜欢
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
  • 2021-06-04
  • 2022-12-23
  • 2021-08-01
  • 2021-10-22
相关资源
相似解决方案