Published by breki on 16 Jan 2009 at 10:28 am
Gallio: Running Tests In Parallel

photo credit: Shahram Sharif
Introduction
Yesterday we finally managed to get our tests to run using our acceptance tests framework. I promise to write more about it some other time, but I’ll make a quick introduction now.
First let’s start with the name of the framework: Accipio. The idea of Accipio is to specify acceptance tests in an XML form which is then automatically translated into MbUnit test code. I guess you can call it a lightweight FitNesse – there’s no Wiki, all test specifications are stored in XML files (which are then source-controlled). The XML is quite simple (you can see some initial brainstorming samples here).
But that’s not what I wanted to talk about now.
Time Is Money, They Say
While running the tests we determined that the whole test process took too long. We had around 100 test cases, each of which had to wait for 10 seconds after the initial action before it could assert the test conditions, which means at least 20 minutes of test running time (and we expect much more test cases to be written in the future). We’ll try to refactor that code so that this wait period is not necessary, but nevertheless these tests are written in a way that should allow parallel execution without any negative effects. In fact the parallelization would be welcome since it mimics the "real" situation in production.
Luckily with little Googling we found a thread on gallio-dev forum called "best way to parallelize a test suite" in which Jeff Brown (Gallio arhictect) discusses a new experimental addition to Gallio – the Parallelizable attribute. It can be applied both to test fixtures and test methods. From what I discerned, the Parallelizable attribute applied on test fixtures means that two or more fixtures can run in parallel, while marking test methods Parallelizable means that two or more test methods in the same fixture run in parallel (I simplified description a little here, for more details please read the mentioned thread).
We needed the second option (parallelization of methods), so I downloaded the latest Gallio package, marked all of our test methods with Parallelizable attribute…
[Metadata("UserStory", "SMSUi.AddSubs.Schedule")]
[Parallelizable]
public void AddScheduledSubs()
{
…
…and run tests with Gallio.Echo runner. So far so good – the test do run in parallel, although occasionally the runner throws some exceptions, we’ll need to investigate this further (after all, this is an experimental feature, so I’m expecting it to break once in a while
.
You can set the rough number of concurrent threads that will process test code by setting DegreeOfParallelism value:
public void FixtureSetup()
{
Gallio.Framework.Pattern.PatternTestGlobals.DegreeOfParallelism = 20;
}
NOTE: I’ve added this code to the fixture setup method because I didn’t know any better place to put it. Also, it would be better not to hard-code it like I did, use a configuration file instead.
Conclusion
Not all tests can be executed in parallel, of course. Once we integrate Selenium into acceptance testing we will have to be careful when selecting which tests should be parallelized and which should not – until we give the Selenium Grid a try, we will have to run Web UI tests on a single thread. I guess the best thing to do is keep non-parallalizable tests in fixtures separate from parallelized ones.



Jeff Brown on 17 Jan 2009 at 11:17 #
This feature will be polished for the v3.0.6 release along with a couple of bug fixes. It will also include an assembly-level attribute to control the degree of parallelism, which should be cleaner than having to modify a global variable as in the current prototype.
Glad you like it!
Rafael on 05 May 2009 at 12:32 #
Man, this is totally awesome. I’ve implemented a thing really alike the Accipio recently and its making wonders at the project i’am. Since we have an agile platform, the only thing that its not changing (too much) are the business requirements. With that, if we had \hard coded\ the tests implementation would be really difficult to maintain, so we had created an DSL (XML + XSD) for tests (that its strictly tight to the business, not even aware of the implementation of the test platform (Selenium) and the application platform (WebApp, ASPX, .NET 3.5). The test files are parsed and then the tests implementations are generated. I was reading about it on your post and felt really ashamed because i thought i had a new idea but u posted a lot earlier than i. But hey, no problem with that, good ideas are to share right
.
If you like to talk about it and discuss some ideas, let me know (i’ve let my email on the post)
C ya and keep up the good work.
breki on 05 May 2009 at 17:06 #
Hi Rafael,
I’m glad you took the same route
. I don’t think I’m the first one though, although I haven’t found any similar tools so far.
I’m wondering what tools did you use to generate the code and execute the tests? I’ve decided on NVelocity for templating.
I haven’t really posted anything about Accipio itself, but if you’re interested, you can see some basic ideas (and code) here:
- http://code.google.com/p/projectpilot/wiki/AutomatedAcceptanceTesting
- http://code.google.com/p/projectpilot/source/browse/#svn/trunk/Accipio
Regards, Igor
yauheni sivukha on 19 Dec 2009 at 13:57 #
I would like to share the sample of ASP.NET application tested with selenium and mbunit. All tests can be runned in parallel.
http://code.google.com/p/design-of-selenium-tests-for-asp-net/
description is here
http://slmoloch.blogspot.com/2009/12/design-of-selenium-tests-for-aspnet_19.html
breki on 19 Dec 2009 at 18:16 #
@yauheni
This looks very interesting, especially since I’m currently working on an ASP MVC project with Selenium testing. Thanks for the links.