Skip to content
/ testkit Public

TestKit is a Go toolkit designed to simplify testing, especially for integration tests involving external services and databases. It offers features like database fixtures, test runners, environment management, SQL helpers, and test lifecycle coordination.

License

Notifications You must be signed in to change notification settings

legrch/testkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Testing Toolkit

Go Reference Go Report Card License Release

A Go toolkit for simplifying testing, particularly for integration tests with external services and databases.

Features

  • Database fixtures: Easily load and reset test data
  • Test runners: Simplified test setup and teardown
  • Environment management: Load environment variables for tests
  • SQL helpers: Utilities for database testing
  • Test lifecycle management: Coordinate test setup and cleanup

Installation

go get github.com/legrch/testkit

Quick Start

Database Test Fixtures

package example_test

import (
	"testing"

	"github.com/legrch/testkit"
)

func TestWithFixtures(t *testing.T) {
	// Load fixtures from JSON files
	fixtures, err := testkit.LoadFixtures("testdata/fixtures")
	if err != nil {
		t.Fatalf("Failed to load fixtures: %v", err)
	}

	// Connect to test database
	db, err := testkit.Connect()
	if err != nil {
		t.Fatalf("Failed to connect to database: %v", err)
	}
	defer db.Close()

	// Apply fixtures to database
	if err := fixtures.Apply(db); err != nil {
		t.Fatalf("Failed to apply fixtures: %v", err)
	}

	// Run tests with loaded fixtures
	// ...

	// Clean up fixtures
	if err := fixtures.Reset(db); err != nil {
		t.Fatalf("Failed to reset fixtures: %v", err)
	}
}

Environment Variable Management

package example_test

import (
	"testing"

	"github.com/legrch/testkit"
)

func TestWithEnvironment(t *testing.T) {
	// Load .env.test file for testing
	env, err := testkit.LoadTestEnv(".env.test")
	if err != nil {
		t.Fatalf("Failed to load test environment: %v", err)
	}
	defer env.Restore()

	// Run tests with environment variables
	// ...
}

Documentation

For detailed documentation, examples, and API reference, please visit:

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

TestKit is a Go toolkit designed to simplify testing, especially for integration tests involving external services and databases. It offers features like database fixtures, test runners, environment management, SQL helpers, and test lifecycle coordination.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages