Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Code generation for test steps #72

Open
bkielbasa opened this issue Feb 20, 2020 · 2 comments
Open

proposal: Code generation for test steps #72

bkielbasa opened this issue Feb 20, 2020 · 2 comments
Labels
enhancement New feature or request proposal

Comments

@bkielbasa
Copy link
Collaborator

bkielbasa commented Feb 20, 2020

Describe the solution you'd like
We discussed in #65 that we want some kind of way of writing less test code.
My idea is to add markers to functions which define the step definition. The first words should be GoBDD step: and after that, there should be a regular expression. Example:

// +gobdd-step: I add (\d+) and (\d+)
func add(ctx context.Context, var1, var2 int) error {
...
}

After calling command gobdd configure generate the command will output a new function definition.

func ConfigureSteps(suite *gobdd.Suite) {
    suite.AddStep(add, `I add (\d+) and (\d+)`)
    // other steps will go here
}

It will be copy&paste ready peace of code. If you provide the -f output.go parameter, the command will parse the output.go code:

  • if there's no ConfigureSteps func, it will add it as the very last function in the file
  • if it exists - it will replace its body.
@bkielbasa bkielbasa added enhancement New feature or request proposal labels Feb 20, 2020
@bkielbasa bkielbasa changed the title Code generation for test steps proposal: Code generation for test steps Feb 20, 2020
@bkielbasa bkielbasa modified the milestone: 1.1 Feb 20, 2020
@mirogta
Copy link
Collaborator

mirogta commented Feb 21, 2020

I like this and I would certainly use this in our team. Would it be clearer if the comment is in a form of a marker and starts with the + sign to differentiate it from normal comments? For example:

// +gobdd-step: I add (\d+) and (\d+)

Would there be also a viable option not to have the ConfigureSteps at all? I've looked deeply at how the https://magefile.org/ works - it's using both build tags and markers and auto-generates a temporary go file (could this in our case contain the ConfigureSteps?), which it then runs, and after the run it removes the temporary file. There's a flag not to delete the generated file, for debugging purposes etc.

@bkielbasa
Copy link
Collaborator Author

Thanks for your comment. I updated the description with the marker.
About skipping the ConfigureSteps function. As I mentioned earlier, I'm not a huge fan of a lot of magic. And what's more, to do it we'll probably have to have an external binary which will generate and remove the file. That's what godog does and this is one of main reasons why this lib was created.

But, if you find an idea of improving it - please create the proposal :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request proposal
Projects
None yet
Development

No branches or pull requests

2 participants