-
Notifications
You must be signed in to change notification settings - Fork 250
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
godog not recognizing the implemented step definition #70
Comments
Hi, godog acts like go test command. your step definitions should be in _test.go files in order to prevent compiling them in production code. All step definitions needs to be registered in godog.Suite all functions godog should be run in root package where your step definitions are in _test.go files. In order to see what step definitions godog finds, you can run You can have a look at examples directory in godog or godog package itself. in order to see how a project and steps are setup. If you still struggle to find the cause, then you can simply create a minimal project with your layout which does not work, so I could help you. Regards, |
What isnt clear in the original issue is that in our configuration features and step definitions exist in multiple child folders. Everything works fine if we run godog from somefunc, and somefunc2 where the steps exist but obviously we are running only one set of tests at a time and not all.
If we run godog from project-root ALL feature files appear to be located just fine, however, the step defs are dont found and executed. Your 3rd paragraph in the response seems to say what we see. It seems that even though feature files can be split up and spread out across the folder structure, the step defs cannot. Godog is looking for one context in the current folder? So to run all tests across the multiple step defs and contexts then we need to run godog multiple times -- once from the location of each step def file? |
when you run go test it compiles _test.go files only from current package directory. because it operates within a package only. (a package is your world). same as godog. I've made godog to be close to go test command and follow the same rules. and your godog test files should be per package only. The idiomatic structure should be:
Otherwise |
I see. Actually I think I missed the fact that go test works similarly. I was thinking go test traversed the tree. We have decided to collapse this structure as a result. Thank you for you responses. |
go test can traverse if you tell it to, but it will compile and run tests for each package separately, godog simply does not provide such option yet, as it is not necessary in most of the cases, because most of users holds on to feature set in core project package including all step definitions in test.go files. and that is an idiomatic way in my opinion, because these are not unit tests and usually you test the public application interface, which is exposed to user (weather it is UI, API or CLI) and that is usually a core project directory or cmd/name dir where users put all their features and step definitions. This is the encouraged way to do project layout. If you put your tests in project root directory including go unit tests, then you get the benefit to use TestMain function in order to get combined go code coverage. This way is also encouraged and it still allows to run godog command separately if different command options are needed. You can also customize TestMain function with cli options when you run tests, like for example controlling verbosity go test -v. From the first look godog may seem to lack features, but these are easily composed if you think the go way of doing things. |
I appreciate your insights on this. We have adjusted our perspective accordingly. Thank you! |
Hey hi, i am having the similar issue. i have written the same code which is mentioned in TestMain, but when i run "go test" it was not able to find the implemented steps. any help..!! |
hi @linuxramu it just may mean two things
running |
thanks for reply, when i ran godog -d, i could see my steps so i am eliminating 1. I couldnt get your 2, can you please give some examples. Also let me give you more info that
My folder structure looks like
So when I run godog tasks.feature from below location, it runs and gives me result correctly c:> mainfolder> tests> godog features/tasks.feature Since my code is growing and i am having more features, now I need to write a driver test or a main test which runs the features as tagged or needed, so thats when this issue is... I have followed to write MainTest as mentioned here : https://github.com/DATA-DOG/godog#running-godog-with-go-test but no luck :( |
with 2. I mean that the regular expression you use is incorrect and it does not match the step. so I'm suggesting to test your regullar expression used for the step definition. godog itself uses godog to test himself. look at this repository how it uses features and how they are structured in the project. the directory you run godog from, must contain all the go files needed for your tests. |
Hi,
I am working in a golang project where in I am writing the gherkin steps and writing step definition
generated by using godog.
My package structure is:
project 's outermost directory contains:
---features(This directory in turn contains below two things)
---features(this is the directorywhich contain .feature files)
-- implemented_step-definition.go file
---Makefile( this is at the same level as outermost features directory)
The issue is that when I run godog with cucumber option under my project 's outermost directory, it recognizes the feature files under the features directory and generates the boiler plate code but it does not run the already implemented step definitions.
Please help me on this .How to make godog run the implemented step definitions from my project's
outermost directory
Thanks,
Ruchira
The text was updated successfully, but these errors were encountered: