cweill / gotests

Automatically generate Go test boilerplate from your source code.
Apache License 2.0
4.92k stars 346 forks source link

Goland generate tests #161

Closed KevinColemanInc closed 3 years ago

KevinColemanInc commented 3 years ago

The docs say you can use goland with this package, but I can't figure it out. Goland has its own "generate action" but the docs don't explain how to customize the template.

Is there an explicit guide on how to use this with Goland?

butuzov commented 3 years ago

Based on screenshots I see a code it generates it's definitely gotests and impl (implement interface), but I have no idea how to configure it. My Gogland says the feature was added n 2021.02, so I guess its pretty fresh. Meanwhile, you can configure these tools in VSCode.

KevinColemanInc commented 3 years ago

For future ppl, I contacted GoLand support and they said they don't provide a way to configure the generator at this time.

You can use an "external tool" + keyboard short cut to simulate the behavior.

Guide

  1. In Goland, Navigate to Preferences | Tools | External Tools and create a new tool.
  2. Specify a name, description, and path to gotests executable.
  3. Add arguments -all -w -template_dir {gotest-template-path}/templates $FileName$
  4. Specify a path to a working directory as $FileDir$.
  5. Check/uncheck advanced options if needed. image
  6. After that, you can navigate to Preferences | Keymap, find your external tool by name and add a shortcut to execute it image
jainsamyak commented 1 year ago

@KevinColemanInc did they also mention if this tool can be used to generate individual function level tests? I believe the above works only for the whole file right?

KevinColemanInc commented 1 year ago

I checked the docs and I don't see how Goland could pass the filename to the tool. Maybe submit a support ticket for better advice.