vendredi 10 janvier 2020

Create test suite and run it using main.go

I'm new to the Golang, but have experience in Java. I have created a testing framework using golang and now I want to create a test suite to run those tests using main.go file without naming the test class as quote_test.go. (without _test part).

My test looks like this. example

quote_test.go

func TestGetQuotes(t *testing.T) {
    quotesAPI := fmt.Sprintf("%s%s", model.BaseURL, model.EndpointQuote)

    var response model.Response

    t.Run("testcase name", func(t *testing.T) {
        requests := &model.Request{
            URL:                quotesAPI,
            RequestFile:        helper.GetFilePath("requestdata", "quotes_unsuccessful.json"),
            HeaderFile:         fmt.Sprintf(filepath.Join("..", os.Getenv("headers"))),
            MethodType:         http.MethodPost,
            ExpectedStatusCode: http.StatusInternalServerError,
        }

        response = helper.ProcessRequestData(requests) //This method will give all the test details to the requests

        helper.DisplayResponseData(t, requests, response)

        var message model.ResponseErrors

        //Unmarshal byteArray which contains booking.json file's content into 'message' variable
        if err := json.Unmarshal([]byte(response.ResponseBody), &message); err != nil {
            t.Error(err)
        }

        assert.NotEmpty(t, response.ResponseBody)
        assert.NotEmpty(t, response.ActualStatusCode)
        assert.Equals(t, "guest creation failed: received status code 500", message.Message)
    })
}

For an ex in TESTNG we can use testsuite.xml file and run it using main.go. As same as i would like to run this test in main.go file and to create binary file. Any ideas?

Aucun commentaire:

Enregistrer un commentaire