mirror of
https://github.com/stretchr/testify.git
synced 2025-05-31 11:42:44 +00:00
allow github syntax highlighting
This commit is contained in:
parent
ce71e91e8d
commit
81cfe446ab
12
README.md
12
README.md
@ -31,6 +31,7 @@ The `assert` package provides some helpful methods that allow you to write bette
|
||||
|
||||
See it in action:
|
||||
|
||||
```go
|
||||
func TestSomething(t *testing.T) {
|
||||
|
||||
// assert equality
|
||||
@ -52,12 +53,14 @@ See it in action:
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
* Every assert func takes the `testing.T` object as the first argument. This is how it writes the errors out through the normal `go test` capabilities.
|
||||
* Every assert func returns a bool indicating whether the assertion was successful or not, this is useful for if you want to go on making further assertions under certain conditions.
|
||||
|
||||
if you assert many times, use the below:
|
||||
|
||||
```go
|
||||
func TestSomething(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@ -78,6 +81,7 @@ if you assert many times, use the below:
|
||||
assert.Equal("Something", object.Value)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`http` package
|
||||
--------------
|
||||
@ -91,6 +95,7 @@ The `mock` package provides a mechanism for easily writing mock objects that can
|
||||
|
||||
An example test function that tests a piece of code that relies on an external object `testObj`, can setup expectations (testify) and assert that they indeed happened:
|
||||
|
||||
```go
|
||||
package yours
|
||||
|
||||
import (
|
||||
@ -143,6 +148,7 @@ An example test function that tests a piece of code that relies on an external o
|
||||
testObj.Mock.AssertExpectations(t)
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/stretchr/testify/mock).
|
||||
|
||||
@ -153,6 +159,7 @@ The `suite` package provides functionality that you might be used to from more c
|
||||
|
||||
An example suite is shown below:
|
||||
|
||||
```go
|
||||
// Basic imports
|
||||
import (
|
||||
"testing"
|
||||
@ -185,6 +192,7 @@ An example suite is shown below:
|
||||
func TestExampleTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(ExampleTestSuite))
|
||||
}
|
||||
```
|
||||
|
||||
For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/stretchr/testify/blob/master/suite/suite_test.go)
|
||||
|
||||
@ -192,6 +200,7 @@ For more information on writing suites, check out the [API documentation for the
|
||||
|
||||
`Suite` object has assertion methods:
|
||||
|
||||
```go
|
||||
// Basic imports
|
||||
import (
|
||||
"testing"
|
||||
@ -222,6 +231,7 @@ For more information on writing suites, check out the [API documentation for the
|
||||
func TestExampleTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(ExampleTestSuite))
|
||||
}
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
@ -240,6 +250,7 @@ This will then make the following packages available to you:
|
||||
|
||||
Import the `testify/assert` package into your code using this template:
|
||||
|
||||
```go
|
||||
package yours
|
||||
|
||||
import (
|
||||
@ -252,6 +263,7 @@ Import the `testify/assert` package into your code using this template:
|
||||
assert.True(t, true, "True is true!")
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user