The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
strange execution order in WordSpec test

2 replies on 1 page. Most recent reply: Sep 14, 2010 11:24 PM by jan helwich

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
jan helwich

Posts: 2
Nickname: janhelwich
Registered: Aug, 2010

strange execution order in WordSpec test Posted: Aug 24, 2010 12:16 AM
Reply to this message Reply
Advertisement
I would expect the code below to succeed. But it doesn't. In fact aNum is 2 at the assert. Is that intended behaviour and if, why?

Thanks in advance and best reards
jan




class TestOfAClass extends WordSpec with ShouldMatchers {

val aclassObj = new AClass

"Changing the var of the obj" when {

"made here" should {

aclassObj.aNum += 1

"the change should be accessible" in {

assert(aclassObj.aNum == 1)

}

}

}

"But it looks like" when {

"the obj is first used here again" should {

aclassObj.aNum += 1

"so aNum in the assert above is 2" in {

pending

}

}

}

}


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: strange execution order in WordSpec test Posted: Sep 14, 2010 1:01 PM
Reply to this message Reply
Sorry I didn't notice this question until today. If you mix in OneInstancePerTest you'll get a different instance of the test class for each test. I believe that will give you the behavior you desire (the kind of behavior JUnit has, for example). The default is to run all tests in the same instance simply because in ScalaTest I wanted code to behave like it looks like it would behave.

jan helwich

Posts: 2
Nickname: janhelwich
Registered: Aug, 2010

Re: strange execution order in WordSpec test Posted: Sep 14, 2010 11:24 PM
Reply to this message Reply
thanks for the answer, bill. i allready noticed a discussion in the mailing list. i tried out specsy and for now it works perfect for the little specs i have for now.

but i will take a look at the OneInstancePerTest, when things become a little more challenging.

regards
jan

Flat View: This topic has 2 replies on 1 page
Topic: XmlReporter encoding problem Previous Topic   Next Topic Topic: Best Practices for Structuring Tests

Sponsored Links



Google
  Web Artima.com   

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