[Lift] Re: unit test framework

2009-07-02 Thread Bill Venners

Hi ph,

If you end up needing to use JUnit, you can import Assertions or
ShouldMatchers or MustMatchers from ScalaTest to get a nicer
scala-like assertion syntax inside JUnit tests. JUnit won't care it
was written in Scala or used ScalaTest assertions and will run it and
generate JUnit-compatible output, since it actually is JUnit. Here's
what that might look like:

import org.junit.Test
import org.scalatest.matchers.MustMatchers._

class MyJUnitTest {
  @Test
  def mapKeys() {
Map(one - 1, two - 2) must contain key (two)
  }
  @Test
  def stringLength() {
hello, world must have length (12)
  }
  @Test
  def stringCharAtMethodRejectsBadInput() {
intercept[StringIndexOutOfBoundsException] {
  hi.charAt(-1)
}
  }
}

http://www.artima.com/scalatest

Bill

On Wed, Jul 1, 2009 at 3:07 PM, phpkirsa...@gmail.com wrote:

 This question might be obvious to most of the people here, but since I
 new to Scala and Java I'm not clear

 Maven generates 2 different unit test files:
 MySpec  specs
 AppTest  junit

 running mvn test invokes AppTest (and other test cases with
 annotation @Test)
 running from Eclipse project as JUnit invokes MySpec

 I'm trying to figure out what unit test framework to use in my
 project. I'd prefer to have JUnit compatible output as continuous
 build system will, probably, understand it.

 Are both test frameworks generate JUnit-compatible output?
 How to make maven invoke specs test when running mvn test?
 Why is it 2 different test frameworks used? Are they complimentary? If
 yes when use which?
 I will probably use Hudson for continuous builds and also invoke unit
 tests from script and or command line and will need parse result and
 generate reports. What framework is better for these purposes? Or
 maybe use both in defferent cases?

 




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

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: unit test framework

2009-07-02 Thread etorreborre

Hi Bill and ph,

Using specs matchers inside a JUnit test class is also possible using
the org.specs.SpecsMatchers trait.

However, I realize that both ScalaTest and specs suffer from the same
issue in that scenario.
When expectations are failing an exception is thrown but it is
interpreted by JUnit as an error instead of a failure.

We should instead throw an AssertionFailedError from the junit
library.

That shouldn't be a big deal to fix.

Eric.

On Jul 3, 10:34 am, Bill Venners b...@artima.com wrote:
 Hi ph,

 If you end up needing to use JUnit, you can import Assertions or
 ShouldMatchers or MustMatchers from ScalaTest to get a nicer
 scala-like assertion syntax inside JUnit tests. JUnit won't care it
 was written in Scala or used ScalaTest assertions and will run it and
 generate JUnit-compatible output, since it actually is JUnit. Here's
 what that might look like:

 import org.junit.Test
 import org.scalatest.matchers.MustMatchers._

 class MyJUnitTest {
   @Test
   def mapKeys() {
     Map(one - 1, two - 2) must contain key (two)
   }
   @Test
   def stringLength() {
     hello, world must have length (12)
   }
   @Test
   def stringCharAtMethodRejectsBadInput() {
     intercept[StringIndexOutOfBoundsException] {
       hi.charAt(-1)
     }
   }

 }

 http://www.artima.com/scalatest

 Bill





 On Wed, Jul 1, 2009 at 3:07 PM, phpkirsa...@gmail.com wrote:

  This question might be obvious to most of the people here, but since I
  new to Scala and Java I'm not clear

  Maven generates 2 different unit test files:
  MySpec  specs
  AppTest  junit

  running mvn test invokes AppTest (and other test cases with
  annotation @Test)
  running from Eclipse project as JUnit invokes MySpec

  I'm trying to figure out what unit test framework to use in my
  project. I'd prefer to have JUnit compatible output as continuous
  build system will, probably, understand it.

  Are both test frameworks generate JUnit-compatible output?
  How to make maven invoke specs test when running mvn test?
  Why is it 2 different test frameworks used? Are they complimentary? If
  yes when use which?
  I will probably use Hudson for continuous builds and also invoke unit
  tests from script and or command line and will need parse result and
  generate reports. What framework is better for these purposes? Or
  maybe use both in defferent cases?

 --
 Bill Venners
 Artima, Inc.http://www.artima.com
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---



[Lift] Re: unit test framework

2009-07-01 Thread etorreborre

Hi,

My understanding is that historically the first tests for lift were
proposed as JUnit tests.
Then I implemented a few tests using specs (which I created), mostly
for the lift-util module.

Now, to answer your question, specs is compatible with JUnit, so you
can write specs and make them runnable with JUnit by writing:

class MySpec extends SpecificationWithJUnit {
  
}
[note1: that this is with specs-1.5.1-SNAPSHOT, with 1.5.0 you would
write extends Specification with JUnit. This was changed to remove
junit dependencies on the Specification class].
[note2: the other, more verbose way, of doing the same thing is to
declare:

class MySpecTest extend org.specs.runner.JUnit(MySpec)
object MySpec extends Specification
]

Then you can also run this specification from the command line with:

scala -cp ... run MySpec

So I would say that eventually this comes down to a matter of taste
when writing tests, whether you prefer the junit or specs syntax.

Eric.

On Jul 2, 8:07 am, ph pkirsa...@gmail.com wrote:
 This question might be obvious to most of the people here, but since I
 new to Scala and Java I'm not clear

 Maven generates 2 different unit test files:
 MySpec  specs
 AppTest  junit

 running mvn test invokes AppTest (and other test cases with
 annotation @Test)
 running from Eclipse project as JUnit invokes MySpec

 I'm trying to figure out what unit test framework to use in my
 project. I'd prefer to have JUnit compatible output as continuous
 build system will, probably, understand it.

 Are both test frameworks generate JUnit-compatible output?
 How to make maven invoke specs test when running mvn test?
 Why is it 2 different test frameworks used? Are they complimentary? If
 yes when use which?
 I will probably use Hudson for continuous builds and also invoke unit
 tests from script and or command line and will need parse result and
 generate reports. What framework is better for these purposes? Or
 maybe use both in defferent cases?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Lift group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~--~~~~--~~--~--~---