Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Testify suite tests not running #1968

Closed
MathiasGr opened this issue Oct 5, 2018 · 14 comments
Closed

Testify suite tests not running #1968

MathiasGr opened this issue Oct 5, 2018 · 14 comments

Comments

@MathiasGr
Copy link
Contributor

MathiasGr commented Oct 5, 2018

Starting from at least 0.6.90, tests bound to testify suites aren't detected by the vscode-go extension. Thus neither codelens or the "Test function at cursor" work anymore for this kind of test.

I also found a second issue while debugging the extension, which drove me crazy because it made the example suite from the testify github page work and show codelenses. The testFuncRegex is missing a ^ in front of Example, which makes the extension treat (suite *ExampleTestSuite) TestExample() like a regular test function, because it includes Example

Last, it should be documented somewhere that even with the fix in #1969 , users need to include "go.gotoSymbol.includeImports": true in their settings for testify to be properly detected.

Steps to Reproduce:

  • Open vscode with the extension enabled and create a test file with the code below
  • Try looking for codelenses and try "Test function at cursor"
package example

import (
	"testing"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/suite"
)

type Suite struct {
	suite.Suite
	VariableThatShouldStartAtFive int
}

func (suite *Suite) TestExample() {
	assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive)
}

func TestSuite(t *testing.T) {
	suite.Run(t, new(Suite))
}

Edit: fix for both issues in #1969

@ramya-rao-a
Copy link
Contributor

Thanks for reporting @MathiasGr! And fixing it too :)

I have pushed your fix to master. Can you try out the beta version of this extension and confirm that the fix works?

@MathiasGr
Copy link
Contributor Author

Thank you for your responsiveness! I can confirm it works again in the beta.

@ramya-rao-a
Copy link
Contributor

This is fixed in the latest update to the Go extension (0.6.91)

@mhr3
Copy link
Contributor

mhr3 commented Oct 11, 2018

Still having a problem with this, even with 0.6.91, does the fix only work with module-based projects or something like that? (also, AFAICT this broke after updating vscode itself, not the extension)

@MathiasGr
Copy link
Contributor Author

MathiasGr commented Oct 11, 2018

@mhr3 did you set the option "go.gotoSymbol.includeImports": true ?

If you did, one issue might be that your suite is defined in another file, and testify/suite isn't imported in your test file. You can fix it by putting this line somewhere in your test file to force the package to be imported:

var _ = suite.TestingSuite(nil)

@mhr3
Copy link
Contributor

mhr3 commented Oct 11, 2018

@MathiasGr No, didn't change the default of that setting.

My test files generally have this in them:

import (
	...
	"github.com/stretchr/testify/suite"
)

type wubsSuite struct {
	suite.Suite

So, it is imported directly

@MathiasGr
Copy link
Contributor Author

Well I'm afraid setting this setting includeImports to true is the only way to fix it right now.

@ramya-rao-a
Copy link
Contributor

@mhr3 Does setting "go.gotoSymbol.includeImports": true help?

@mhr3
Copy link
Contributor

mhr3 commented Oct 12, 2018

Sorry, missed that it's now required to set includeImports to true for this to work. And it indeed does after changing it.

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Oct 12, 2018

@mhr It is not required to have that setting to have this feature to work. Its an unfortunate side effect of a refactoring I had done last week.

I have pushed a fix to master to take care of this. Can you try the latest beta version of this extension? testify should be supported there with and without the includeImports setting.

@mhr3
Copy link
Contributor

mhr3 commented Oct 15, 2018

How do I get the beta? The link you posted points to this issue...

@ramya-rao-a
Copy link
Contributor

@mhr3 Sorry about that! The link is updated.

@mhr3
Copy link
Contributor

mhr3 commented Oct 15, 2018

Thanks, and yep, works fine with the beta, even without includeImports.

@ramya-rao-a
Copy link
Contributor

The fix is now out in the latest update to the Go extension (0.6.92)

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants