Golang testify: Difference between revisions
From wikinotes
(Created page with "Testify is a 3rd party test library for golang.<br> It includes assertions and mocks. = Documentation = <blockquote> {| class="wikitable" |- | github || https://github.com/st...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Testify is a 3rd party test library for golang.<br> | Testify is a 3rd party test library for golang.<br> | ||
It includes assertions and mocks. | It includes assertions and mocks. | ||
It's functionality is modular, opt in to the features you are interested in. | |||
* assert | |||
* require | |||
* mock | |||
* suite | |||
= Documentation = | = Documentation = | ||
Line 10: | Line 17: | ||
|} | |} | ||
</blockquote><!-- Documentation --> | </blockquote><!-- Documentation --> | ||
= Install = | |||
<blockquote> | |||
<syntaxhighlight lang="bash"> | |||
go get github.com/stretchr/testify | |||
</syntaxhighlight> | |||
</blockquote><!-- Install --> | |||
= Usage = | |||
<blockquote> | |||
== Assertions == | |||
<blockquote> | |||
All assertions allow passing a more descriptive message. | |||
<syntaxhighlight lang="go"> | |||
import ( | |||
"github.com/stretchr/testify/assert" | |||
) | |||
assert.Equal(t, expects, result) | |||
assert.Equal(t, expects, result, "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 --> |
Latest revision as of 00:30, 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, expects, result) assert.Equal(t, expects, result, "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