gstest

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package gstest is a unit testing framework designed for dependency injection in go-spring. Unlike standard dependency injection, in unit testing mode, the framework gracefully ignores non-critical dependency injection failures by logging warnings instead of halting execution. This ensures seamless testing workflows when dealing with extensive dependencies, as only the specific dependencies under test need to be validated, while others remain non-blocking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[T any](t *testing.T) T

Get gets the bean from the app context.

func TestMain

func TestMain(m *testing.M, opts ...RunOption)

TestMain executes test cases and ensures shutdown of the app context.

func Wire

func Wire[T any](t *testing.T, obj T) T

Wire injects dependencies into the object.

Types

type BeanMock

type BeanMock[T any] struct {
	// contains filtered or unexported fields
}

BeanMock is a mock for bean.

func MockFor

func MockFor[T any](name ...string) BeanMock[T]

MockFor creates a mock for bean.

func (BeanMock[T]) With

func (m BeanMock[T]) With(obj T)

With registers a mock bean.

type RunOption

type RunOption func(arg *runArg)

func AfterRun

func AfterRun(fn func()) RunOption

AfterRun specifies a function to be executed after all testcases.

func BeforeRun

func BeforeRun(fn func()) RunOption

BeforeRun specifies a function to be executed before all testcases.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL