The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
execute test cases in order

2 replies on 1 page. Most recent reply: Dec 18, 2011 4:53 PM by J Camphor

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
J Camphor

Posts: 2
Nickname: camphor
Registered: Dec, 2011

execute test cases in order Posted: Dec 17, 2011 5:11 PM
Reply to this message Reply
Advertisement
How to execute test cases in order?

I have two test cases named T001_xxx.scala and T002_xxx.scala which both extend FunSuite.
("xxx" are some Japanese characters.

[T001_xxx.scala]
class T001_xxx extends FunSuite {
test("T001_xxx") {
...
}
}

Execute via apache-ant:
<scalatest>
<wildcard package="x.y.z" />
<runpath>omit...</runpath>
<reporter type="iunitxml" directory="..." />
</scalatest>

Scalatest runs in the following order:
(1) T002_xxx
(2) T001_xxx

But I hope in the following:
(1') T001_xxx
(2') T002_xxx

Why?
I see the source of DiscoverySuite.scala and 'nestedSuiteNames' which returns List generated from Set.

[part of DiscoverySuite.scala]
private[scalatest] def nestedSuiteNames(path: String, accessibleSuites: Set[String], wildcard: Boolean): List[String] =
if (wildcard)
wildcardList(path, accessibleSuites).toList
else
narrowList(path, accessibleSuites).toList

To execute in the desired order:

[my solution: addition of 'sortWith(_ < _)']
private[scalatest] def nestedSuiteNames(path: String, accessibleSuites: Set[String], wildcard: Boolean): List[String] =
if (wildcard)
wildcardList(path, accessibleSuites).toList.sortWith(_ < _)
else
narrowList(path, accessibleSuites).toList.sortWith(_ < _)

This solution results in the desired order.
Is there any other better solution[s]?

[versions]
scalatest: 1.6.1
scala: 2.9.1
java: 1.7.0
apache-ant: 1.8.2


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: execute test cases in order Posted: Dec 17, 2011 11:30 PM
Reply to this message Reply
The intended way to execute suites in order is to create a suite with nested suites.


class OrderedSuite extends Suites(
new Test001_XXX, new Test002_xxx
)


Then instead of using discovery, actually specify OrderedSuite directly:


<scalatest>
<suite classname="x.y.z.OrderedSuite" />
<runpath>omit...</runpath>
<reporter type="iunitxml" directory="..." />
</scalatest>


If you want to use discovery because you have a bunch of other suites that you don't want to hard-code as nested suites, then you can make Test001_xxx and Test002_xxx "invisible" to discovery by giving them a one-arg constructor. It can take any object and ignore it. (You'll have to pass an object in when you construct it.) This will cause discovery to pass it by, because it only discovers Suites with public, no-arg constructors. (In 2.0 there will be a DoNotDiscover annotation you could use to disable discovery, but for now you'll have to put in the one-arg constructor). Here's an example:


class Test001_xxx(o: Any) extends FunSuite ...
class Test002_xxx(o: Any) extends FunSuite ...

object CloakingDevice
class OrderedSuite extends Suites(
new Test001_XXX(CloakingDevice),
new Test002_xxx(CloakingDevice)
)

J Camphor

Posts: 2
Nickname: camphor
Registered: Dec, 2011

Re: execute test cases in order Posted: Dec 18, 2011 4:53 PM
Reply to this message Reply
Thanks a lot.

It is true: 'you don't want to hard-code as nested suites'

I don't want to write the word of 'Test00n_xxx' twice (or more times).



I'm looking forward to be released verion 2.0.

thx

Flat View: This topic has 2 replies on 1 page
Topic: instantiate a test database Previous Topic   Next Topic Topic: junit-addons

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use