Golang testify: Difference between revisions
From wikinotes
No edit summary |
(→Usage) |
||
Line 27: | Line 27: | ||
= Usage = | = Usage = | ||
<blockquote> | <blockquote> | ||
== Assertions == | |||
<blockquote> | |||
All assertions allow passing a more descriptive message. | |||
<syntaxhighlight lang="go"> | |||
import ( | |||
"github.com/stretchr/testify/assert" | |||
) | |||
assert.Equal(t, 123, 123) | |||
assert.Equal(t, 123, 123, "they should be equal") | |||
</syntaxhighlight> | |||
Assertions | |||
<syntaxhighlight lang="go"> | |||
assert.Equal(t, 123, 123) | |||
assert.NotEqual(t, 123, 100) | |||
assert.NotNil(t, 123) | |||
</syntaxhighlight> | |||
</blockquote><!-- Assertions --> | |||
== Mocks == | |||
<blockquote> | |||
haven't used yet | |||
</blockquote><!-- Mocks --> | |||
== Suite == | |||
<blockquote> | |||
haven't used yet | |||
</blockquote><!-- Suite --> | |||
</blockquote><!-- Usage --> | </blockquote><!-- Usage --> |
Revision as of 00:28, 12 December 2022
Testify is a 3rd party test library for golang.
It includes assertions and mocks.
It's functionality is modular, opt in to the features you are interested in.
- assert
- require
- mock
- suite
Documentation
github https://github.com/stretchr/testify
Install
go get github.com/stretchr/testify
Usage
Assertions
All assertions allow passing a more descriptive message.
import ( "github.com/stretchr/testify/assert" ) assert.Equal(t, 123, 123) assert.Equal(t, 123, 123, "they should be equal")Assertions
assert.Equal(t, 123, 123) assert.NotEqual(t, 123, 100) assert.NotNil(t, 123)Mocks
haven't used yet
Suite
haven't used yet