-
Notifications
You must be signed in to change notification settings - Fork 645
Unit test generation should consider the receiver type #2282
Comments
Thanks for reporting @Guitarbum722 So looks like all we need to do is identify the receiver type, convert it to title case, prepend it to the function name and then pass the resulting string to PRs are welcome to fix this
|
@ramya-rao-a I'm new here. I would like to give it a try 👏 |
I tried a couple of other scenarios that should probably be taken into consideration for this. As mentioned, the receiver type can be prepended to the function's name in the regexp passed to So, I would think the Go Extension would need to do the same thing to normalize the regexp passed to |
@jamesgeorge007 Yes, the changes should be done inside Thanks for the note @Guitarbum722 |
@ramya-rao-a I'm a newbie here. I didn't get it really what you meant by the receiver here. |
Is this the code-part to be considered within the |
@open-source-explorer That would give just the function name, where as what we need is the receiver type as well. Since Regarding receivers, https://tour.golang.org/methods/3 is a simple introduction |
@ramya-rao-a I'm not sure on how to retrieve the receiver type in this context 🤔 |
One of the properties would be |
This issue has been resolved in the latest beta version of this extension. |
This issue has been resolved in the latest version (0.13.0) of this extension Thanks for the PR @marcel-basel and Thanks for reporting @Guitarbum722! Happy Coding! |
Description:
The Go Plugin doesn't seem to consider the receiver type for a method. So, if there are
>=
1 method names in the same file, then clicking "generate unit tests for function" creates test functions for all of them.This references an issue with
gotests
. However, that same gotests issue explains that the receiver type is in fact supported.I tried this by running the following (as an example) in the command line using
gotests
directly.$ gotests -w -only ^PersonValidate$ .
This works as expected, and there is only a test function generated for the
Person
type.Version of VS Code, the Go plugin and Go:
VSCode:
1.30.2 61122f88f0bf01e2ac16bdb9e1bc4571755f5bd8 x64
Go Plugin:
0.8.0
Go: 1.11.2 darwin/amd64
OS/Platform you are working on
MacOS / AMD64
Reproducible steps (1... 2... 3...) that cause the issue
What you expected to see, versus what you actually saw
I would expect that the Go extension uses
gotests
with the-only
flag and prepends the type name with the regexp. Therefore, one single test function is generated for the respective method that was selected.Instead, any methods that have the same name in the file have a test function generated.
Great extension though! 👍 Hopefully this is enough info.
The text was updated successfully, but these errors were encountered: