Fitnesse: how to initialize/tearDown suite (not individual test) - fitnesse

I have a basic question:
When using JUnit, in your test suite (the class that holds your tests) you can declare suite-level initialization and cleanUp behaviour using #BeforeClass and #AfterClass. The methods thusly annotated are called before the suite begins and after the suite finishes all its tests respectivelly. This differs from the methods inside the suite which are annotated with #Before and #After which are called before each test is launched and after each finishes respectivelly.
I want the same setup in Fitnesse. I found out how to have stuff that's executed before and after each test (you create a SetUp page and a TearDown page in the suite, and they'll be called before and after each test in the suite). These are the equivalent of #Before and #After in JUnit. I can't however understand how can I declare a suite-level initialization and cleanUp logic (like #BeforeClass and #AfterClass in JUnit). Can someone please tell me if/how this can be achieved?
What I've tried is have a parent suite with SetUp and TearDown pages, and INSIDE that parent suite have mutlipl child suites which contain the actual tests (each with it's own SetUp and TearDown), hoping that this way the parent suite SetUp and TearDown pages will be called before and after each child suite, and the child suite's SetUp and TearDown pages will be called before and after each test in the suite, but no dice, what happends here is that the child suite SetUp/TearDown overrides the parent suite ones.

SuiteSetUp and SuiteTearDown - see http://www.fitnesse.org/FitNesse.FullReferenceGuide.UserGuide.WritingAcceptanceTests.SpecialPages

Related

Sharing code between multiple Kiwi test files

I have some Kiwi test helper code that is useful across most of my specs.
What's a nice way of sharing this code across multiple specs (i.e. multiple files)? A category on KiwiSpec might be one option. But that feels a bit off, since I'd be putting code in that category to make things work, rather than because it actually belongs in KiwiSpec.
The 'shared example' feature of Kiwi (since 4.2.0) seems to be better for DRY in a single spec/file, rather than across multiple specs.
The main reason I can't just call some external code from my test is that this external code isn't inside a test case/Kiwi spec, so its assertions either generate compile errors or warnings.
Update
I've tried injecting the assertion functionality needed by the external test helper code as blocks into the helper code. (This has the advantage that my test helper code is not then hard-coded to use any particular test framework.) This was only partially successful: for the test cases where I'm expecting an exception to be raised:
[[theBlock(...) should] raise];
none is raised. I suspect the problem is that I have another block being called inside the main block which has a raise against it.
Update 2
Another possible technique is suggested at https://github.com/kiwi-bdd/Kiwi/issues/138 by user gantaa, whereby we create a self variable pointing to the test suite object outside the context of the test suite.

Dart - How run a function after or before each test?

I'm using the Dart test package: https://pub.dartlang.org/packages/test
Often, I want to run some function before or after each tests in my test file. Does the test package provide something for this?
add a setUp(() { add your code here}) before your test() function.
There is also a tearDown() which is run after each test.
If you add the setUp function at top level in main it is run for every test, if you put it inside a group it is run for every test in that group. You can have setUp/tearDown on more than one level at the same time.
tearDown is executed in any case (like finally) no matter if the test fails or succeeds.
Recently setUpAll() and tearDownAll() was added to do some set up and tear down once before and after all tests.

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.

Jbehave - Run method after a specific scenario

I'm trying to configure JBehave with Gherkin to run a teardown method after a specific scenario. So far I'm aware of the below:
JBehave supports Gherkin, which has a syntax for Lifecycle before
event, unfortunately Gherkin doesn't support the Lifecycle after.
http://jbehave.org/reference/latest/story-syntax.html
JBehave supports the annotation #AfterScenario which can only be specified to on the outcome of the scenario. This is run after all scenarios in a story rather after a specific scenario.
http://jbehave.org/reference/latest/annotations.html
At the moment I have include a Gherkin step (#Then teardown this sceanrio) at the end my scenario within my story. This contradicts the point of BDD which should only display what the user is doing and not what the test needs to do.
Unfortunately there isn't a way to access the META tags in the after scenario methods. As a workaround that doesn't require you to duplicate your entire scenario file couldn't you leave all of the scenarios from your current class that don't require the teardown where they are, and move the one that does need the teardown into its own class which inherits from the first class. Then, add the after scenario method to the second class.

How to set the transactionnal option per test class in a spock integration test?

In a grails project (version 2.3.7) , i have an integration test using Spock :
class SimpleIntegrationTests extends IntegrationSpec{
void "test an action from controller to database"(){...}
}
This integration test launch a batch with Spring Batch. Spring batch does not accept when a batch is launched from an existing transaction :
java.lang.IllegalStateException: Existing transaction detected in JobRepository. Please fix this and try again
So i tell my integration test to run without transaction, with :
static transactional = false
Doing this, the test runs with success.
But there are other integration tests in my project, which need transactions to run correctly.
And the instruction "transactionnal = false" in my test class is not confined to this test class, but affects all other integration tests triggered after my test class.
I understood there is an alphabetically execution order for the tests. So i know that if i rename my test class to be the last test class to run, it works fine, and all my tests are successful. But i think it s not an ideal answer to the problem.
So my question is : how to define that a test class is non transactionnal, in a manner that does not affect other integration tests ?
I know this is an old question and I imagine you've found a solution already, but as a work around I think you need to explicitly specify static transactional = true on integration tests that you still want to be transactional. We've had a similar issue with our Grails 2.3.7 test suite...

Resources