How to run tests in a specific order with ginkgo? - ginkgo

I use ginkgo to write some tests, including:
books_suite_test.go
install_test.go
reading_test.go
isbn_test.go
uninstall_test.go
how to run these tests in a specific order as following:
install_test.go -> reading_test.go -> isbn_test.go -> uninstall_test.go
I found ginkgo can not ensure the test order. Is there any way to do this?

User the Ordered keyword in your Describe-block to run the block as a "Ordered Container".
https://onsi.github.io/ginkgo/#ordered-containers
You should not build tests that rely on tests of other files. Because the dirty answer to your question is that it's possible to put Containers and It-blocks into functions and call them in the order you desire
Ordered Container

Related

Nested grep option in Mocha (or another way of selecting exacly one test)

In Mocha we can use --grep flag for selecting specific test for running:
mocha --grep 'my test'
But when numbers of tests raises, come specific test cases can share the same name, what makes single grep insufficient. I'd love to have something like "nested grep" to be able to select tests more specifically, regarding its parents. Can it be possible? Or maybe there are some other options to select a test for running more specific way?
Okay, fortunately I discovered that we can do something like this:
mocha /path/to/specific/file -g 'pattern for specific test case'
It solves my problem as long as case names don't repeat in the scope of one file (but they generally shouldn't).

How do I use --order option in Rspec to order files

I want to run feature specs written in rspec/capybara in a fixed sequence as follows:
signup_spec.rb
login_spec.rb
project_creation_spec.rb
project_migration_spec.rb
The --order feature of given here says that
Use the --order option to tell RSpec how to order the files, groups, and
examples
How would I use .rspec file to mention pass my requirements ?
I have a shell script with test cases running in a sequence like:
rspec spec/features/signup_spec.rb
rspec spec/features/login_spec.rb
rspec spec/features/project_creation_spec.rb
rspec spec/features/project_migration_spec.rb
The order option does not allow this. It allows switching between the default ordering (which is essentially that they are run in the order they are defined which in turns depends on file system ordering ) or random ordering (optionally with a seed)
I would consider any order dependence to be a bug - the random ordering option is there to flush out such bugs.

Grails Test Suite - Specify test order

I am trying to get my geb-spock functional tests to run in a specified order because SpecA will create data required for SpecB during its run.
This question is about running the specifications in order, not the individual test methods within the specification.
I have tried changing the specification name to indicate execution order but that didn't work. I found a solution where a Test Suite was used, and the tests were added to the suite in order, but I can't find how to make a test suite work in Grails.
Explicitly specifying them as grails test-app functional: SpecA SpecB , is not a long term option, as more specs will be added.
For sequential or whatever the sequence you want to run your tasks, I do the following thing in my build.gradle file:
def modules = ["X", "Y", "Z", "ZZ"]
if (modules.size() > 1) {
for(j in 1 .. modules.size()-1 ) {
tasks[modules[j]].mustRunAfter modules[values[j-1]]
}
}
Hope that helps. Cheers!
Not really an answer to your question but a general advice - don't do this. Introducing data setup dependencies between test classes will make your suite brittle in the long run. Reasoning about what the state is at a given point will get harder and harder as the amount of tests grows and the global state size with it. Later on hanging a test or introducing a new one might break many tests downstream. This is just asking for trouble.
Ideally, you want to setup the data needed by a test immediately before that test and tear it down afterwards. Grails Remote Control plugin and test data fixture builders are your friends here.
You should define your initialization code in a single place, and if it's shared between both Specs, it may be a good idea to create a superclass with methods you can call in each Spec's set up methods, or a whole class devoted to declare testing methods to reuse.
In any case, the purpose of a unit test is only to test a single functionality, and it shouldn't be responsible of setting up other tests as well.

Reordering the test cases in a FitNesse test suite

I have a test suite with tests ordered as:
Suite1---A
B
C
How can I change the order of the test cases?
I have tried refactoring but that is not helping.
It doesn't look this is possible...
Remember, that the order tests run is alphabetical. So in the above example, TestThree will not run because TestTwo actually comes after TestThree
--FitNesse > UserGuide > TestSuites > TagsAndFilters
...but it shouldn't matter. Tests should be independent and not rely upon previous tests (other than SuiteSetUp).

The After hook in cucumber

Folks,
I am having some trouble working with the Afterhook. I have organized my tests in folders like this:
features/Accounts/accounts_api.feature
features/Accounts/step_definition/account_steps.rb
features/labs/create_lab.feature
features/labs/step_definition/labs_steps.rb
Now I have an After hook present in the step definition of the Accounts feature, I want that hook to run after every scenario of the "Accounts" feature, but I do not want it to run after every scenario of the "labs" feature. I tried this:
cucumber --tags #newlabs
the above should run all the scenarios present in the labs feature tagged as newlabs but what I am seeing is that once the scenario tagged as#newlabs runs the #after hook present in the step definition of Accounts starts to run. I am thinking why is this happening, am I using the hook in the wrong way or is my overall understanding of hooks wrong?
Thanks a lot for taking the time to respond, this helps a lot.
Hooks don't care what step definition script they're located in and will run for every scenario. Or, more specifically, your after hook will run after every scenario that runs, for every feature, regardless of the tags you pass in to Cucumber.
If you want a little more control over that, check out the Cucumber wiki page on hooks and look in the section called 'Tagged hooks'.
Possibly you define After hook in wrong place. Note that After hook (as well as other hooks) must be defined in the .rb, not in the .feature file. Common place for hooks is features/support/hooks.rb. You will define your hook this way:
# features/support/hooks.rb
After('#newlabs') do # will run after each scenario tagged with #newlabs
# your teardown ruby code
end
# features/Accounts/accounts_api.feature
#newlabs # tag all scenarious of this feature with #newlabs tag
Feature: your feature
Scenario: your scenario
Given: ...
When: ...
Then: ...
In cucumber output you won't see that After hook is executed (unless you output something to STDOUT from the hook definition) - hooks will run implicitly.

Resources