Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apitester : API testing package

Overview GoDoc

Package to unittest test golang API with json request and responses.

Install

go get github.com/akash1729/apitester

Example

package usage

import (
	"testing"

	"github.com/akash1729/apitester"
)

func GetUserTests(t *testing.T) {

	testCase := apitester.TestCase{
		TestName:    "CreateUser",
		TestDetail:  "Proper Implemetaion",
		Route:       "/User",
		Method:      "POST",
		HandlerFunc: CreateUser, //import and assign corresponding handler
		StatusCode:  200,
		AvoidKey:    []string{"token"},
		RequestHeader: map[string]string{
			"Authorization": "authorization key",
		},
		RequestMap: map[string]interface{}{
			"username": "nitya",
			"password": "password"},
		ResponseHeader: map[string]string{
			"Content-Type": "application/json",
		},
		ResponseMap: map[string]interface{}{
			"status":   "User Created succesfully",
			"userID":   88,
			"username": "nitya"},
		TypeCheck: map[string]interface{}{
			"token":    "stringType",
			"userID":   0,
			"username": "stringType",
		},
		RequestContextKey:   "requestID",
		RequestContextValue: 123,
	}

	apitester.RunTest(&testCase, t)

}

Only HandlerFunc Field is mandatory All other fields are optional during testing

Author

Akash Thomas

License

MIT.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages