The Artima Developer Community
Sponsored Link

Weblogs Forum
ScalaTest 0.9.1 Released

29 replies on 2 pages. Most recent reply: Jan 28, 2008 11:42 AM by Cedric Beust

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 29 replies on 2 pages [ « | 1 2 ]
Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 8:34 AM
Reply to this message Reply
Advertisement
> I agree.
>
> Quick Question: The only reason why you were overriding
> runTest was to set the gen variable? You no longer need
> it? If thats true, then fantastic.
>
Yes, in this case, you wouldn't need to override runTest.

If you ever want to, you can override a bunch of methods in Suite to do run tests differently. So for example, I do think I should have an ImpSuite in the API for people who are comfortable with setUp and tearDown-like methods. In ImpSuite I'd override runTest so that it calls setUpFixture before, and tearDownFixture after, invoking the test method.

People spend so much time writing tests, and it is hard to convince people to write them, that I want people to feel it is easy with ScalaTest to write tests however they want. I'd like to provide enough variations on the theme to please most people, so they wouldn't need to override runTest or execute, etc. But if the have some special need or desire, they could override these methods and then be able to write tests exactly like they prefer.

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 9:20 AM
Reply to this message Reply
If you want to make it as easy as possible, you know you're going to need IDE support right?

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 10:12 AM
Reply to this message Reply
> If you want to make it as easy as possible, you know
> you're going to need IDE support right?
>
Yes. I haven't yet contacted the Scala plug-in folks, but I'd really like to help them incorporate ScalaTest support into those plug-ins like JUnit is supported by default in Java IDEs. So that's my first angle.

The IDE situation for Java is so nice that the situation for Scala looks quite grim in comparison. I am looking forward to trying the NetBeans plug-in. Just haven't had time to try it yet. The Eclipse plug-in seems pretty good except I think IntelliJ spoiled me for Eclipse. Eclipse is nice enough but I just don't feel as happy in it for some reason.

One thing currently missing I feel is IDE support that allows people to effectively manage hybrid apps where part of the app is in Scala and part in Java. One way I figured people could potentially get into Scala is by writing tests in Scala to test Java code. In the Eclipse plug-in the Scala and Java code has to be in different projects or at least modules. Are you using TestNG that way? I'm curious how you're able to run the TestNG tests you write in Scala right from your IDE. Do you compile the Scala-written tests with a build script, i.e., with scalac or fsc, and then run the .class file?

One other thing I want to make sure is easy is to use Java collections in ScalaTest tests. I haven't tried that. There's a compatibility library in the Scala API that I tried to use once, but didn't have much success. I need to try that again. That's one use case I want to make sure is easy to do, so that if people want to try writing tests for Java code in Scala they can easily do that, even though the Java code uses Java collections.

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 10:43 AM
Reply to this message Reply
You're right about how I'm running TestNG with Scala. As I said in my most recent blog, its a pain. I didn't really explain, but I will now.

First, I cant just right click the Scala file and do Run As -> TestNG test. Cedric said Alex might get back to me on seeing if we could add that support.

What I was able to accomplish was running it through a TestNG XML file, right clicking on it and Run As -> TestNG Test. The xml file is simple, as you can see here: http://cpusimulator.googlecode.com/svn/trunk/testng-scala-tests.xml

But, I was only able to do this after calling my Ant target to compile all my code and tests. But even then there is some weird interaction that I still need to figure out. The eclipse Scala plugin is compiling the files to the bin directory. I'm compiling them into target. There are classpath issues and each time before I run the tests I have to do Project -> Clean. Such a pain. Most of the time I get frustrated and just run them though Ant, which I could also do with specs, so I almost moved to specs.

But, every once in a while when I have a failing tests, its so nice to be able to run them in the IDE and really dig in and figure out whats going on. Its not nearly as nice doing that though Ant.

I'd obviously like to see full IDE support for all these frameworks so I could really evaluate all of them properly.

Does ScalaTest run through Ant?

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 12:13 PM
Reply to this message Reply
Are you dead set on the name ScalaTest? Theres already ScalaCheck and specs, and scunit, its hard to keep track of which one is which.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 3:35 PM
Reply to this message Reply
> Does ScalaTest run through Ant?
>
We should have an ScalaTest ant task soon, but for now you can use the scala or java ant tasks. This is how I run it from ScalaTest's own build file:


<path id="test.class.path">
<pathelement location="${dist}/lib/scalatest.jar"/>
<pathelement location="${lib}/scala-library.jar"/>
</path>

<target name="test" depends="dist">
<!-- Delete the ${build} and ${dist} directory trees -->
<java classname="org.scalatest.Runner" classpathref="test.class.path" fork="true">

<arg value="-p"/>
<arg value="build_tests"/>

<arg value="-g"/>
<arg value="-o"/>

<arg value="-s"/>
<arg value="org.scalatest.AllSuite"/>
</java>
</target>


Basically the args are command line args, as documented in Runner:

http://www.artima.com/scalatest/doc-0.9.1/org/scalatest/Runner$object.html

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 3:36 PM
Reply to this message Reply
> Are you dead set on the name ScalaTest? Theres already
> ScalaCheck and specs, and scunit, its hard to keep track
> of which one is which.
>
Probably will stick with ScalaTest. I want people to immediately know it is about Scala and testing.

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 3:42 PM
Reply to this message Reply
Thanks for the Ant stuff.

I always thought that Sweet would be the best name for a unit test framework, ever. But, I'm kinda goofy.

Lets see...

Sweet
ScalaTestSweet
SweetScalaTest

Anyway, I just talked to Cedric and he said he had no bandwidth for much related to TestNG and Scala. I really want to work on a Scala test framework, so, keep me filled in if I can help.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 25, 2008 8:24 PM
Reply to this message Reply
> I always thought that Sweet would be the best name for a
> unit test framework, ever. But, I'm kinda goofy.
>
> Lets see...
>
> Sweet
> ScalaTestSweet
> SweetScalaTest
>
Or just "Suite!". SuiteRunner I thought wasn't bad, but it was too long and a bit boring.

> Anyway, I just talked to Cedric and he said he had no
> bandwidth for much related to TestNG and Scala. I really
> want to work on a Scala test framework, so, keep me filled
> in if I can help.
>
Well, since you're doing TestNG stuff, would you like to work on the org.scalatest.testng package? The first thing to be done is hopefully a trait, but maybe a class, named TestNGSuite, which extends Suite and overrides execute. The goal is to be able to write test classes using TestNG annotations that can be run with either as TestNG test classes or as ScalaTest Suites. This would allow people to write TestNG classes in Scala like you've been wanting to do, but they can use more Scala-like assertion syntax provided by ScalaTest, as in:


@Test(groups = { "checkin-test" })
class All extends TestNGSuite {

@Test(groups = { "func-test" )
def method1() {
expect(List(1, 2)) {
List(1) ::: List(2)
}
}

def method2() {
assert(List(1, 2) === 1 :: List(2))
}
}


Ideally people could do anything in those classes that they could do in a regular TestNG class, and have it do the same thing TestNG would do when you invoke execute on it. The way I figured we could do that is to actually ask TestNG to run the Suite. So what TestNG.execute would need to do is somehow translate the parameters that are being passed into execute into something a TestNG runner understands, so that the tests would be run by TestNG's code and reports sent back to the ScalaTest Reporter that was passed to execute.

What I was planning to do next was integrate with ScalaCheck, then JUnit 3, and after that try TestNG. But if you want to try it that would be great.

The other thing I wanted to have in org.scalatest.testng was probably a class called TestNGWrapperSuite, which extends Suite and simply wraps existing TestNG tests, which are most likely written in Java. The idea would be that you could start writing new tests in Scala, continue to maintain and enhance your existing TestNG tests in Java, and run them all together with ScalaTest. So that is the other task in that area. Interested in trying your hand at this?

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 26, 2008 9:06 AM
Reply to this message Reply
I finally got the svn repository up at java.net. It doesn't have all the history i my private svn repository, which I'll keep around. It just starts at the 0.9.1 release. Here's the URL:

https://scalatest.dev.java.net/source/browse/scalatest/

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 26, 2008 10:30 AM
Reply to this message Reply
Great. I started poking around this morning, but only long enough to find the main page: https://scalatest.dev.java.net/. I'll get the code at some point this weekend.

I'll review it all and read through the documentation and make some initial attempts at the TestNG integration soon.

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 26, 2008 6:26 PM
Reply to this message Reply
Oh, any by that I meant, yes, I'm totally interested.

Joshua Cough

Posts: 20
Nickname: joshcough
Registered: Jan, 2008

Re: ScalaTest 0.9.1 Released Posted: Jan 26, 2008 8:44 PM
Reply to this message Reply
Bill,

My very first attempt at this seems to have been met with great success. There's still work to do but all in all its not too shabby. Here is the code, followed by a test you can use:


package org.scalatest.testng;

import org.scalatest.Suite
import org.testng.TestNG
import org.testng.TestListenerAdapter
import org.testng.ITestResult

trait TestNGSuite extends Suite{

override def execute(testName: Option[String], reporter: Reporter, stopper: Stopper, includes: Set[String], excludes: Set[String],
properties: Map[String, Any], distributor: Option[Distributor]) {

runTestNG(reporter);
//super.execute(testName, reporter, stopper, includes, excludes, properties, distributor)
}

private class MyTestListenerAdapter( reporter: Reporter ) extends TestListenerAdapter{
val className = TestNGSuite.this.getClass.getName

override def onTestStart(result: ITestResult) = {
reporter.testStarting( buildReport( result, None ))
}

override def onTestSuccess(itr: ITestResult) = {
reporter.testSucceeded( buildReport( itr, None ))
}

override def onTestFailure(itr: ITestResult) = {
reporter.testFailed( buildReport( itr, Some(itr.getThrowable)))
}

private def buildReport( itr: ITestResult, t: Option[Throwable] ): Report =
new Report(className + "." + itr.getName, className )
}

private def runTestNG(reporter: Reporter) : TestListenerAdapter = {
val tla = new MyTestListenerAdapter(reporter);
val testng = new TestNG();
testng.setTestClasses(Array(this.getClass));
testng.addListener(tla);
testng.run();
tla
}

}



import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test

class MySuite extends TestNGSuite {

@Test
def testAddition() {
val sum = 1 + 1
assert(sum === 2)
assert(sum + 2 === 4)
}

@Test
def testSubtraction() {
val diff = 4 - 1
assert(diff === 3)
assert(diff - 2 === 1)
}

@Test
def testSubtraction2() {
val diff = 4 - 1
assert(diff === 3)
assert(diff - 2 === 78)
}

}


I'm assuming I don't need to explain to you how to run them, since you built the system. Let me know otherwise.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: ScalaTest 0.9.1 Released Posted: Jan 26, 2008 9:40 PM
Reply to this message Reply
>
> My very first attempt at this seems to have been met with
> great success. There's still work to do but all in all its
> not too shabby. Here is the code, followed by a test you
> can use:
>
Hey Cedric, if you're watching, this worked like a charm. We figure its a testament to the good design of TestNG. Josh's MySuite is a TestNG test class written in Scala, which can be run either via TestNG or ScalaTest. Josh and I spoke on the phone briefly tonight to discuss to-do items, but there weren't too many. I'm adding Josh to the java.net project and with any luck we'll have TestNG integration stuff in the next release of ScalaTest.

Thanks, Josh.

Cedric Beust

Posts: 140
Nickname: cbeust
Registered: Feb, 2004

Re: ScalaTest 0.9.1 Released Posted: Jan 28, 2008 11:42 AM
Reply to this message Reply
Very happy to read that, nice work, guys!

--
Cedric

Flat View: This topic has 29 replies on 2 pages [ « | 1  2 ]
Topic: ScalaTest 0.9.1 Released Previous Topic   Next Topic Topic: Ruby + DSLs = Power Tool

Sponsored Links



Google
  Web Artima.com   

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