Search code examples
gotestify

Difference between SetupSuite & SetupTest in Testify Suites


I am trying to figure out difference between SetupSuite and SetupTest for quite some time now. Based on information on blogs I have understood that SetupSuite is run before entire suite and SetupTest runs before each test case. But what could be practical example in such a case? And how does dependency injection differ in both the cases?


Solution

  • Generally you want to use SetupTest so that each individual test function runs with a clean environment. SetupSuite is useful in cases where the setup code is time consuming and isn't modified in any of the tests. An example of when this could be useful is if you were testing code that reads from a database, and all the tests used the same data and only ran SELECT statements. In this scenario, SetupSuite could be used once to load the database with data.