package monster
import (
_"fmt"
"encoding/json"
"io/ioutil"
_"os"
)
type Monster struct{
Name string
Age int
Skill string
}
func (monster *Monster) Store() bool {
str,_ := json.Marshal(monster)
filename := "D:/a.txt"
ioutil.WriteFile(filename, []byte(str), 0777)
return true
}
package monster
import (
_"fmt"
"testing"
)
func TestMonster(t *testing.T){
var moster = Monster{
Name:"张三",
Age:20,
Skill:"会员",
}
res := moster.Store()
if res != true {
t.Fatalf("错误")
}
t.Logf("正确")
}
go test -v .\moster_test.go .\monster.go
- 结果集
