Ordering jbehave stories (.feature) to run sequentially, non-random order

1,373 views
Skip to first unread message

Joe Colantonio

unread,
Sep 30, 2014, 9:49:42 AM9/30/14
to thucydid...@googlegroups.com

I’m currently using the findStoriesCalled(*.feature) to run all my feature files in my project. The issue is that it runs the stories in a random order. I would like to read from a property file called test suite where I can list the order in which I want the .feature files to run. I’m trying to debug an issue which I think is caused by certain .feature files but it’s hard to reproduce without being able to run the .feature files in the same order.

I know that in JBehave without using Thucydides you can override the storyPaths() but when I try doing this I get a class loader issue. Anyone have any ideas how to run BDD tests in Thucydides in a set order?


Thanks

Adrian Mitev

unread,
Oct 1, 2014, 3:35:04 AM10/1/14
to thucydid...@googlegroups.com
Ordering tests is considered a bad practice. Your tests have to be isolated so you can run a single test without the need to run the others before it. In addition to run your test suite faster, the tests have to run in parallel and in this case you can't rely on the test order.

Joe Colantonio

unread,
Oct 1, 2014, 5:57:21 AM10/1/14
to thucydid...@googlegroups.com
Hi Adrian

Thanks for helping. I know its considered a "bad practice" thats why this is for debugging purposes only. When I run in CI normally it would read in my property file that has *.feature. BUT I'm having an issue that makes it near impossible due to the randomness.

Thanks,

Joe

Richard Cruceanu

unread,
Oct 1, 2014, 9:43:22 AM10/1/14
to thucydid...@googlegroups.com
Hi Joe,
   I had the same problem and I fixed it by overriding storyPaths(). Here is the thread with my solution.
   I fixed any class loader issues by using the default directory structure for Thucydides and configuring my project settings in IntelliJ (the IDE I use).

Cheers,
Richard

Joe Colantonio

unread,
Oct 1, 2014, 10:34:20 AM10/1/14
to thucydid...@googlegroups.com
Hi Richard,

This is awesome. I actually saw this a few days ago and have been struggling to get your code example working for me. I keep getting a class loader error no matter what path I use

com.jc.hcit.radtests.bdd.DesktopTestSuite: Story path 'DiagnosticHub.feature' not found by class loader

Where do you have your code? I place this in my runner class that extends ThucydidesJUnitStories 

Thanks!

Joe

Richard Cruceanu

unread,
Oct 2, 2014, 10:03:53 AM10/2/14
to thucydid...@googlegroups.com
Hi Joe,
   I don't know exactly why the class loader fails for you, so here is a detailed look at my environment.
   
Good luck,
Richard

project Behavior structure:
Behavior/
target/ <--- folder excluded in IntelliJ used as output
src/
main/
java/ <--- folder marked as source code in IntelliJ
com/company/bdd/ <--- location of java classes which interact with the system
test/
java/ <--- folder marked as test source code in IntelliJ
com/company/bdd/ <--- location of the TestRunner.java
steps/ <--- location of step classes used in the stories, which use the classes in com.company.bdd to access the system
resources/ <--- folder marked as test resource folder in IntelliJ
stories/ <--- location of all my *.stories files (I think you named them *.feature).
capability/feature/story.story <--- standard hierarcy of story files, all placed under the stories folder.

-----------------------------------------------
The compile output of the project is redirected.
output path: Behavior/target/classes
test output path: Behavior/target/test-classes

-----------------------------------------------
In IntelliJ there is a project file (Behavior.iml), in which the folder assignment is kept. 
If the order of the folders in this file gets changed then stories are not found properly.
Here is an excerpt of the project file:
  <component name="NewModuleRootManager" inherit-compiler-output="false">
    <output url="file://$MODULE_DIR$/target/classes" />
    <output-test url="file://$MODULE_DIR$/target/test-classes" />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
      <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
      <excludeFolder url="file://$MODULE_DIR$/target" />
    </content>
-----------------------------------------------------------

I run TestRunner as a jUnit test configuration with a work folder set to Behavior and a command line paramenter: -Dstories=<stories file without extension>

TestRunner class:

public class TestRunner extends ThucydidesJUnitStories
{
    protected String getStoriesFile()
    {
        String storiesFile = System.getProperty("stories");
        String parentFolder = System.getProperty("user.dir");
        String storiesPath = "\\src\\test\\resources\\stories\\";
        return parentFolder + storiesPath + storiesFile + ".stories";
    }

    @Override
    public List<String> storyPaths()
    {
        try
        {
            File file = new File(getStoriesFile());
            try (FileReader reader = new FileReader(file))
            {
                char[] buffer = new char[(int) file.length()];
                reader.read(buffer);
                String[] lines = new String(buffer).split("\n");
                List<String> storiesList = new ArrayList<>(lines.length);
                for (String line : lines)
                {
                    if (!line.startsWith("#"))
                    {
                        storiesList.add(line.trim());
                    }
                }
                return storiesList;
            }
        }
        catch (Throwable e)
        {
            System.out.println(StringUtil.exceptionToString("failed to load stories list", e));
            throw new RuntimeException(e);

Ali Ostadsaraie

unread,
Oct 2, 2014, 4:03:57 PM10/2/14
to Richard Cruceanu, thucydid...@googlegroups.com
When I try this:
 System.getProperty("stories");

it returns null.

Any idea why?


--
You received this message because you are subscribed to the Google Groups "Thucydides Users Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thucydides-use...@googlegroups.com.
To post to this group, send email to thucydid...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Cruceanu

unread,
Oct 2, 2014, 5:43:14 PM10/2/14
to Ali Ostadsaraie, thucydid...@googlegroups.com
Add  command line paramenter: -Dstories=<stories file without extension>

Richard

Joe Colantonio

unread,
Oct 27, 2014, 4:55:08 PM10/27/14
to thucydid...@googlegroups.com
Thanks Richard for such a detailed reply! I've tried your code, but unfortunately  I can't get past this not found by class loader sun.misc.Launcher$AppClassLoader@41556f4c error. I'll post an update once I figure it out
Reply all
Reply to author
Forward
0 new messages