Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixtures framework for Go tests

License

NotificationsYou must be signed in to change notification settings

orsinium-labs/fixie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fixtures framework for Go tests.

Installation

go get github.com/orsinium-labs/fixie

Usage

Create a fixture:

funcwithUser(c fixie.C)User {returnUser{}}

Create a registry and register all fixtures:

varfixtures=fixie.NewRegistry()funcinit() {fixie.Register(fixtures,withUser)}

In tests, create a fixie context:

funcTestUser(t*testing.T) {c:=fixie.NewC(t,fixtures)// ...}

Now that you have a testing context, you can access values:

user:= fixie.Get[User](c)

The first time you call it,fixie.Get will find a fixture that produces a value of the given type, call it, and cache and return the result. On subsequent calls, the cached value will be used. The cache is local to the context, so it's safe to use witht.Parallel.

The best part is that you can access values from other fixtures as well:

funcwithAdmin(c fixie.C)Admin {user:= fixie.Get[User](c)returnAdmin{User:user}}

Languages


[8]ページ先頭

©2009-2025 Movatter.jp