In a simple case of two required parameters, there are four possible test cases IIUC:
- both empty
- first set but not second
- second set but not first
- both set
What is best practice, test all four cases?
Because even testing the first and last cases is quite verbose in Golang:
func TestGoodParameter(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
q := req.URL.Query()
q.Add("first", "foo")
q.Add("second", "bar")
req.URL.RawQuery = q.Encode()
rec := httptest.NewRecorder()
root(rec, req)
res := rec.Result()
if res.StatusCode != http.StatusOK {
t.Errorf("got %v, expected %v", res.StatusCode, http.StatusOK)
}
}
func TestBadParameter(t *testing.T) {
req, _ := http.NewRequest("GET", "/", nil)
rec := httptest.NewRecorder()
root(rec, req)
res := rec.Result()
if res.StatusCode != http.StatusBadRequest {
t.Errorf("got %v, expected %v", res.StatusCode, http.StatusBadRequest)
}
}
Or are there some tricks I am missing here? It obviously gets even more complicated when say there are five parameters where two of them are optional!