1. 程式人生 > >go語言中的單元測試編寫

go語言中的單元測試編寫

  • 測試檔案 my_test.go 的檔名字尾必須為 _test,檔名前半部分可隨意取。
  • 測試函式 Test0001,Test0002等,函式名必須以 Test 字首,函式名後半部分可隨意取,引數必須為 (test *testing.T)。
package main

import (
	"awesomeProject/oop/employee"
	"testing"
)

func TestAdd(t *testing.T) {
	println("add")
}

func TestSub(t *testing.T) {
	println("sub")
	e := employee.Employee{
		FirstName:   "Sam",
		LastName:    "Adolf",
		TotalLeaves: 30,
		LeavesTaken: 20,
	}
	e.LeavesRemaining()
}