The Artima Developer Community
Sponsored Link

ScalaTest/ScalaUtils Forum
a bit of feedback

3 replies on 1 page. Most recent reply: Jan 22, 2008 9:00 PM by Bill Venners

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 3 replies on 1 page
Brian Slesinsky

Posts: 43
Nickname: skybrian
Registered: Sep, 2003

a bit of feedback Posted: Jan 15, 2008 9:53 AM
Reply to this message Reply
Advertisement
I haven't tried it out yet, but from looking at the documentation:

- The expected and actual values are reversed compared to JUnit. In JUnit, the expected value comes first. I think this is reasonable, but it's important to emphasize the change because it's easy to get wrong. (Similarly, the location of the message is reversed.)

- expectNPE and expectIAE are very opaque; a good function name should be understandable without looking it up. How about naming them throwsNull and throwsIllegalArg?

- Iit would be nice if support for test names beginning with "should" as well as "test" were the default.

- What's the argument for omitting setUp() and tearDown()?

- Any test should easily be run by itself, interactively, and it's unclear how to do this if it requires a certain test suite.


Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: a bit of feedback Posted: Jan 15, 2008 8:11 PM
Reply to this message Reply
> I haven't tried it out yet, but from looking at the
> documentation:
>
> - The expected and actual values are reversed
> compared to JUnit. In JUnit, the expected value comes
> first. I think this is reasonable, but it's important to
> emphasize the change because it's easy to get wrong.
> (Similarly, the location of the message is reversed.)
>
I didn't realize they were reverse from assertEquals. I'll point that out in the documentation. One of the things I thought was dumb about JUnit originally was that the optional message to assertEquals comes first. Something optional usually comes second. The reason I put actual first is that's the thing we're curious about. It just seemed the natural way to say it.

> - expectNPE and expectIAE are very opaque; a good function
> name should be understandable without looking it up. How
> about naming them throwsNull and throwsIllegalArg?
>
Yes, they are obscure. Eventually Scala may have a way to express non-nullness in the type system, and if so, an NPE may be a rare thing to check for. I don't like your particular suggestions either, but expectIAE is definitely obscure. It could be dropped entirely and added or something else added later based on actual demand. The things I check for most are NPE and IAE though.

> - Iit would be nice if support for test names beginning
> with "should" as well as "test" were the default.
>
Can you explain why you think this? Perhaps give an example?

> - What's the argument for omitting setUp() and
> tearDown()?
>
Basically setUp and tearDown encourage mutable state, and so it kind of goes against the grain of the more functional style encouraged by Scala. Normally you'd reassign mutable instance variables in setUp, clean them up in tearDown, do it again for the next test, etc. What I wanted to encourage instead is that if you really need to share something between test methods, try and make it a val instance variable, not a var. If you can't do that, then you can override any of several methods to do something before and after.

The real difference between ScalaTest and JUnit3/4/TestNG is that in ScalaTest you ask a suite of tests to execute itself by calling its execute method. In JUnit3/4/TestNG the framework executes suites of tests from the outside. This enables people to override execute in ScalaTest for all different kinds of situations to execute tests in custom ways, something that you can't do easily in JUnit3/4/TestNG. One thing you could do, for example, is make a Suite subtrait that calls setUp and tearDown before each test method. When I make the Suite subtraits that support JUnit3/4/TestNG, that's exactly what they'll do. So not having setUp and tearDown is just the default Suite approach. Subtraits and Subclasses of Suite can override that behavior if they want.

> - Any test should easily be run by itself, interactively,
> and it's unclear how to do this if it requires a certain
> test suite.
>
There's an execute method that takes one String, which is the name of a test inside that Suite to execute. You just say something like:


(new MySuite).execute("testAddition")


It will go through all the before and after code you may have added in overridden methods, and then just invoke that one test.

Brian Slesinsky

Posts: 43
Nickname: skybrian
Registered: Sep, 2003

Re: a bit of feedback Posted: Jan 22, 2008 8:04 PM
Reply to this message Reply
>> - Iit would be nice if support for test names beginning
>> with "should" as well as "test" were the default.
>>

>Can you explain why you think this? Perhaps give an example?

It lets you write test names such as "shouldNotOverflow" or "shouldNotBeEqualWhenNameIsDifferent" that more clearly describe what you are asserting.

If you search on "behavior-driven development" you'll discover some frameworks people are writing in languages such as Ruby that are supposedly easier to use than JUnit. They look like syntactic sugar to me, and the main thing I got out of it is that test names that start with "should" tend to read well.

These frameworks also tend to initialize a value in a setUp() method and then put one assertion in each test method. The name of the test method documents what the assertion is meant to prove, hence "should". That seems a bit fine-grained in Java but perhaps it would make sense in Scala.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: a bit of feedback Posted: Jan 22, 2008 9:00 PM
Reply to this message Reply
> >> - Iit would be nice if support for test names
> beginning
> >> with "should" as well as "test" were the default.
> >>
>
> >Can you explain why you think this? Perhaps give an
> example?
>
> It lets you write test names such as "shouldNotOverflow"
> or "shouldNotBeEqualWhenNameIsDifferent" that more clearly
> describe what you are asserting.
>
> If you search on "behavior-driven development" you'll
> discover some frameworks people are writing in languages
> such as Ruby that are supposedly easier to use than JUnit.
> They look like syntactic sugar to me, and the main thing
> g I got out of it is that test names that start with
> "should" tend to read well.
>
> These frameworks also tend to initialize a value in a
> setUp() method and then put one assertion in each test
> method. The name of the test method documents what the
> assertion is meant to prove, hence "should". That seems a
> bit fine-grained in Java but perhaps it would make sense
> in Scala.
>
I see. Finer grained tests. I do remember hearing Dave Astels a long ago saying you should have one assertion per test method. It would be simple enough to discover "should" methods as well as "test" methods, but I'll wait on that. The Ruby framework I'm aware of is RSpec, and there's a Scala framework inspired by RSpec called Specs:

http://code.google.com/p/specs/

Cedric Beust mentioned to me that he preferred method names starting with "should". Now I see where that's coming from. However, RSpec and Specs seem to place the should in a string that is like a human language specification of what should happen. I spoke with Eric TorreBorre, who is doing Specs, and we'd like to integrate. What I'd like is that people could Specs matchers as an optional way to write tests in ScalaTest. I'll email Dave Astels and ask him to take a look at the framework and give his opinion as well.

Flat View: This topic has 3 replies on 1 page
Topic: provide a RunnerJPanel Previous Topic   Next Topic Topic: Scala versions

Sponsored Links



Google
  Web Artima.com   

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