How to use both both Funspec and Funsuite (or FunspecLike and FunsuiteLike) in the same test class declaration

391 views
Skip to first unread message

akkat...@gmail.com

unread,
Feb 25, 2015, 8:07:17 PM2/25/15
to scalate...@googlegroups.com
Hi
I am trying to write a ScalaTest class as follows:

class MyActorUnitTest extends FunSpec
with MustMatchers
with ScalaFutures
with BeforeAndAfter 
with FunSpecLike{

test("Test my actor's behaviour")



}

Now, when I try to compile or run sbt test it complains that 
I would also like to leverage the Akka Test Kit. So i tried writing as below.
But I cannot compile it again, because it complains that I can't use both Funspec and Funsuite at the same time. Besides And the test() method is only available if I extend from Funsuite or (mix in) the Funsuite 
Trait.

And, if I do something like below.  

class MyUnitTest(_system: ActorSystem) extends TestKit(_system)
  //with FunSpecLike
  with FunSuiteLike
  with ScalaFutures
  with MustMatchers
  with BeforeAndAfter {

     test("...")

}

It works. And it does not complain about "test()".

If I leave out FunsuuiteLike and bring in FunSpecLike, then I can't bring in "test()". 

class MyActorUnitTest(_system: ActorSystem) extends TestKit(_system)
  with FunSpecLike
  //with FunSuiteLike
  with ScalaFutures
  with MustMatchers
  with BeforeAndAfter {

     test("...")   //this cause it to not compile or sbt test fails

}'

So, what do I do? I am not so familiar with the practice of mixing in traits, it seems.

I would like to use both FunspecLike and FunSuiteLike and I would like TestKit as shown above.

Please advise me on a solution to my issue.

Bill Venners

unread,
Feb 26, 2015, 4:53:10 PM2/26/15
to scalate...@googlegroups.com
Hi,

Sorry for the delay in responding. I couldn't answer right away
yesterday and forgot to go back later until I saw your forum post.

You will need to select between FunSpecLike and FunSuiteLike. If you
want to write tests with test("your test's name"), then you'll want
FunSuiteLike, like this example:

class MyUnitTest(_system: ActorSystem) extends TestKit(_system)
//with FunSpecLike
with FunSuiteLike
with ScalaFutures
with MustMatchers
with BeforeAndAfter {


test("...")

}

Can I ask why you also want FunSpecLike in there? Perhaps if I
understood what you're after I could suggest a different way to get
it.

Thanks.

Bill
> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
> ---
> You received this message because you are subscribed to the Google Groups
> "scalatest-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to scalatest-use...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Bill Venners
Artima, Inc.
http://www.artima.com

akkat...@gmail.com

unread,
Feb 26, 2015, 8:34:43 PM2/26/15
to scalate...@googlegroups.com
The reason I am "stuck" with FunSpecLike is because where I work, tests were written using FunSpec, and even introducing TestKit was frowned upon and discouraged.
I did not argue because they knew best.
Now, the only reason I want to use FunsSuite also, seems to be to bring the 'test()" method into my tests, which I think makes my test class more readable.
Other than that, I am naive at this point about whether there is any real advantage to using both FunSpecLike and FunsSuiteLike (if I extend from TestKit)
However I did study both the FunspecLike and FunsuiteLike traits and the only solid piece of learning I derived from this, was that both traits were remarkably similar.
Except for the "test()" method.

If I do not bring in Funspec, I will incur someone else's displeasure (and I do not fault them at all), but I would like to bring in the the "benefits" of testkit" along with FunspecLike
and FunsuiteLike. 
So, I have to keep FunsSpec and I dont find anything wrong with it. It gets the job done for the most part and gets the mission accomplished.

So that is my dilemma.
And yes, I would like a different way of bringing in "FunSpecLike" to sit with "FunsuiteLike". If that is possible. 

--
No problem, about replying when you could. I appreciate your taking the time to answer.
Thanks for the help.

----
Ian
Reply all
Reply to author
Forward
0 new messages