The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
ScalaTest not executing before all

2 replies on 1 page. Most recent reply: Oct 27, 2015 11:25 AM by Lisa Tran

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
Lisa Tran

Posts: 2
Nickname: lisatran
Registered: Oct, 2015

ScalaTest not executing before all Posted: Oct 27, 2015 10:17 AM
Reply to this message Reply
Advertisement
Hi All,
I have a scala test which extends flatspec style with BeforeAndAfterAll.

My problem is it's not running beforeall with shared tests in behavior functions style.For example:
class TestBeforeAll extends FlatSpec with BeforeAndAfterAll{

var abc :String = "bla"

def printWord(word :String): Unit =
{
println("The word is :"+word)
}
override def beforeAll() =
{
print("In before all")
abc = "Hello"
}

"A Stack" should behave like printWord(abc)

}


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest not executing before all Posted: Oct 27, 2015 10:51 AM
Reply to this message Reply
> Hi All,
> I have a scala test which extends flatspec style with
> BeforeAndAfterAll.
>
> My problem is it's not running beforeall with shared tests
> in behavior functions style.For example:
> class TestBeforeAll extends FlatSpec with
> BeforeAndAfterAll{
>
> var abc :String = "bla"
>
> def printWord(word :String): Unit =
> {
> println("The word is :"+word)
> }
> override def beforeAll() =
> {
> print("In before all")
> abc = "Hello"
> }
>
> "A Stack" should behave like printWord(abc)
>
> }
>
Hi Lisa,

beforeAll will happen before tests, but you didn't register a test in the printWord(abc) method, just did a println. You need to do something like:



def printWord(word :String): Unit =
{
"A widget" should ("print this word: " + word) in {
println("The word is :"+word)
}
}

Lisa Tran

Posts: 2
Nickname: lisatran
Registered: Oct, 2015

Re: ScalaTest not executing before all Posted: Oct 27, 2015 11:25 AM
Reply to this message Reply
Thanks Bill for the quick reply .it's running before all now:)

However, I want before all to override my var(abc) to hello but it's printing bla ..How can I do that?

Flat View: This topic has 2 replies on 1 page
Topic: TestFailedException should be an error and not a RuntimeException Previous Topic   Next Topic Topic: java.lang.IllegalArgumentException: ERROR: -c has been deprecated

Sponsored Links



Google
  Web Artima.com   

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