0

Am using testify's test suite support to write unit tests. This results in my test file having a single TestFooBar(t *testing.T) that kicks of the suite.Run while all my individual tests become a part of my test suite struct with method signatures like - func (suite *myTestSuite) TestMyStuff().

I have observed that GoLand can identify all methods with a signature similar to TestFooBar(t *testing.T) and put a green play icon next to it. It will allow me to run/debug these methods individually. However, all the test methods that are a part of the test suite as described above, won't be identified and cannot be ran or debugged individually in the IDE.

Any way to tell GoLand that myTestSuite structure has many tests that will allow me to execute them individually inside the IDE?

(Similar question here but that is just talking about command line, while my question is specifically for the IDE.)

amitsaurav
  • 531
  • 1
  • 5
  • 18
  • Why use testify it it makes things harder? – Volker Aug 31 '18 at 10:45
  • Is there a way other than testify that will let me write code that'll run - beforeTestSuite, beforeTest, afterTest and afterTestSuite? I can do it all manually if I did not have testify but wondering if there's a better way. – amitsaurav Aug 31 '18 at 11:24
  • Curious about the downvotes. Am I missing something here or do golang people really hate testify? – amitsaurav Aug 31 '18 at 11:45
  • Testify brings back old crap to some nice testing package and polluting it. – Volker Aug 31 '18 at 11:50
  • Ok, am a newbie when it comes to golang and stumbled upon testify for writing test fixtures. What are some options that you'd recommend for unit tests that require setting up and tearing down, if not testify? – amitsaurav Aug 31 '18 at 11:55
  • Most tests should not need complicated setup work to be performed: Shove data into a function and check the returned results. Shove data into a method and check results returned and state of the object. If your fixtures set up complicated database clusters then this crosses the integration- or system-test border even for me. Take a look at the stdlib which has tests for lots of different things. – Volker Aug 31 '18 at 12:11
  • Testify is a good framework, despite what others in this thread claim. I'm sorry you are experiencing issues with getting it to work in the IDE, see my answer why. Do not be let down by the answers here and continue to work on getting your Go skills better using any tools/packages that can help you out. – dlsniper Sep 01 '18 at 12:37
  • I have the same problem with testify. Previously I worked with gocheck. The support was better in Goland, but gocheck does not have rich assertions. I think these two are still the most common test frameworks for Go and they certainly should be supported. @Volker your comment about tests not needing complicated setup are incorrect. Maybe you don't have too much experience with testing large systems. Integration tests typically do need this support. The fact that finding a test framework is so difficult is just another of the compromises you need to make when choosing to program in Go. – David Sackstein Mar 15 '22 at 11:50

2 Answers2

0

At the moment, the IDE does not support recognizing tests from testify. There's an issue for that, https://youtrack.jetbrains.com/issue/GO-3066, and we hope we'll get it done soon.

As a workaround, you can edit manually a Run Configuration via Run | Edit Configurations... | + | Go Test and pass the arguments to the Go Tool in order to pick up the test that you need to debug.

dlsniper
  • 7,188
  • 1
  • 35
  • 44
0

Workaround: Remove the suite receiver, do the test and then put the suite receiver back.

Cyro
  • 609
  • 5
  • 11