doc.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Package suite contains logic for creating testing suite structs
  2. // and running the methods on those structs as tests. The most useful
  3. // piece of this package is that you can create setup/teardown methods
  4. // on your testing suites, which will run before/after the whole suite
  5. // or individual tests (depending on which interface(s) you
  6. // implement).
  7. //
  8. // The suite package does not support parallel tests. See [issue 934].
  9. //
  10. // A testing suite is usually built by first extending the built-in
  11. // suite functionality from suite.Suite in testify. Alternatively,
  12. // you could reproduce that logic on your own if you wanted (you
  13. // just need to implement the TestingSuite interface from
  14. // suite/interfaces.go).
  15. //
  16. // After that, you can implement any of the interfaces in
  17. // suite/interfaces.go to add setup/teardown functionality to your
  18. // suite, and add any methods that start with "Test" to add tests.
  19. // Methods that do not match any suite interfaces and do not begin
  20. // with "Test" will not be run by testify, and can safely be used as
  21. // helper methods.
  22. //
  23. // Once you've built your testing suite, you need to run the suite
  24. // (using suite.Run from testify) inside any function that matches the
  25. // identity that "go test" is already looking for (i.e.
  26. // func(*testing.T)).
  27. //
  28. // Regular expression to select test suites specified command-line
  29. // argument "-run". Regular expression to select the methods
  30. // of test suites specified command-line argument "-m".
  31. // Suite object has assertion methods.
  32. //
  33. // A crude example:
  34. //
  35. // // Basic imports
  36. // import (
  37. // "testing"
  38. // "github.com/stretchr/testify/assert"
  39. // "github.com/stretchr/testify/suite"
  40. // )
  41. //
  42. // // Define the suite, and absorb the built-in basic suite
  43. // // functionality from testify - including a T() method which
  44. // // returns the current testing context
  45. // type ExampleTestSuite struct {
  46. // suite.Suite
  47. // VariableThatShouldStartAtFive int
  48. // }
  49. //
  50. // // Make sure that VariableThatShouldStartAtFive is set to five
  51. // // before each test
  52. // func (suite *ExampleTestSuite) SetupTest() {
  53. // suite.VariableThatShouldStartAtFive = 5
  54. // }
  55. //
  56. // // All methods that begin with "Test" are run as tests within a
  57. // // suite.
  58. // func (suite *ExampleTestSuite) TestExample() {
  59. // assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
  60. // suite.Equal(5, suite.VariableThatShouldStartAtFive)
  61. // }
  62. //
  63. // // In order for 'go test' to run this suite, we need to create
  64. // // a normal test function and pass our suite to suite.Run
  65. // func TestExampleTestSuite(t *testing.T) {
  66. // suite.Run(t, new(ExampleTestSuite))
  67. // }
  68. //
  69. // [issue 934]: https://github.com/stretchr/testify/issues/934
  70. package suite