jeudi 9 mai 2019

Function TestMain didn't run

Seems like my func TestMain didn't run

i have 2 file in my test folder /_test one is /main_test.go another one is /api_city_find_all_test.go

i run the second one and there's panic error says that i got nil pointer i tried printout something in my /main_test.go in func TestMain but it didn't print anything, seems like the main_test.go didn't work/run

anyone can help me with this?

main_test.go

func TestMain(m *testing.M) {

  fmt.Print("TEST@@")

  os.Chdir("../../../")

  boot.Bootstrap()

  rajaongkir.Register()

  os.Exit(m.Run())
}


i run api_city_find_all_test.go

func TestApiCityFindAllTest(t *testing.T) {
  goreq := libraries.Request("http://localhost:8181").Post([]string{"rajaongkir/city/findAll"}, nil, `{}`)

  req, _ := goreq.MakeRequest()
  resp := httptest.NewRecorder()

  fmt.Print("TEST!!")

  utilities.Globals.Router.ServeHTTP(resp, req)

  respBody, _ := ioutil.ReadAll(resp.Body)

  t.Log(string(respBody))

  assert.NotEqual(t, "null", string(respBody))
}

i expect the "TEST!!" in api_rajaongkir_city_find_all_test.go and "TEST@@" in main_test.go are printed but just "TEST!!" shown up, it means the main_Test.go didn't run

Aucun commentaire:

Enregistrer un commentaire