Skip to content

goca test-integration

Generate integration test scaffolding for a named entity. The generated tests exercise the full request-to-database stack in a temporary test environment.

Syntax

bash
goca test-integration <EntityName> [flags]

Description

goca test-integration creates an integration test file under internal/testing/tests/ that:

  • Spins up an in-memory or test database
  • Runs the full use-case and repository stack
  • Provides HTTP request helpers when a handler is present
  • Uses testify/suite for setup and teardown lifecycle

Flags

--dry-run

Preview the files that would be created without writing anything to disk.

bash
goca test-integration Product --dry-run

--force

Overwrite existing integration test files.

bash
goca test-integration Product --force

--backup

Back up existing test files to .goca-backup/ before overwriting.

bash
goca test-integration Product --backup

Examples

Generate integration tests for one entity

bash
goca test-integration Order

Preview without writing

bash
goca test-integration Order --dry-run

Generated Files

FileDescription
internal/testing/tests/order_integration_test.goFull integration test suite

Generated Code Example

go
// Code generated by goca. DO NOT EDIT by hand.
package tests

import (
    "testing"
    "github.com/stretchr/testify/suite"
)

type OrderIntegrationSuite struct {
    suite.Suite
    // db, repo, usecase, handler fields
}

func (s *OrderIntegrationSuite) SetupSuite() { /* setup test DB */ }
func (s *OrderIntegrationSuite) TearDownSuite() { /* cleanup */ }

func TestOrderIntegration(t *testing.T) {
    suite.Run(t, new(OrderIntegrationSuite))
}
  • goca feature — generate all layers including integration tests via --integration-tests flag
  • goca mocks — generate unit test mocks for the same entity

Released under the MIT License.