Scalatest not working on any tests I add (in Scala IDE 3.0.3)

101 views
Skip to first unread message

Mark

unread,
Apr 8, 2014, 2:48:35 AM4/8/14
to scalate...@googlegroups.com
Hi all. I've spent the past four hours trying to get a single test to run with the scalatest plugin for the Scala IDE.  I've attempted to follow all directions I've seen here:  http://www.scalatest.org/user_guide/using_scalatest_with_eclipse, so this is the best place I know to ask for some help.

Details:

Both the IDE and the plugin are fresh installs. I put the plugin in a lib directory that is sibling to my source directory and I've added the scalatest library to my project via right clicking my project and using the build configurations page.  I've written an extremely simple suite of 2 tests for a < 50 line app.  None of the advertised features are working.  I can't right click the tests to run them, no results pane comes up, etc...  Right-clicking the test suite file and going to Run As...brings up only Run Configurations...

Is there anything obvious I'm missing?  What's the fastest way to get this working so I can actually start writing code instead of messing with the IDE and related tools?

Chee Seng Chua

unread,
Apr 8, 2014, 8:40:53 AM4/8/14
to scalate...@googlegroups.com
Hi Mark, 

It's a known problem inherited from scala-ide launching code, the problem is that the package declaration of DeckSuite does not match the directory structure.  If you change the package declaration of DeckSuite to blackjack.test then it should work.  The same problem apply to Run As -> Scala Application, if you create a Main with package declaration different than directory structure the menu is not popping up also.  It was quite a long time ago that I discussed this problem with Mirco Dotta, as best I can remember is that the problem is related to JDT behavior so unfortunately it is not an easy one to fix.

Hope this helps.

Cheers, 
Chee Seng


--
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.

Mark

unread,
Apr 8, 2014, 3:05:23 PM4/8/14
to scalate...@googlegroups.com
Thanks for the quick reply!  I tried changing the package of DeckSuite to blackjack.test and then importing blackjack as so:

package blackjack.test

import blackjack._


But, it didn't fix it.  There are no errors in eclipse, but when I right click on DeckSuite, there are no options under Run as -> Run Configurations


Any other ideas?  Do you know of any simple tutorial to actually get this library working in Eclipse?  I don't know the Java ecosystem at all, so I need the simplest possible thing to get started.

Bill Venners

unread,
Apr 8, 2014, 3:07:02 PM4/8/14
to scalate...@googlegroups.com
Hi Mark,

I'm not sure if you saw this already or not, but our tutorial is here:

http://scalatest.org/user_guide/using_scalatest_with_eclipse

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

Mark

unread,
Apr 8, 2014, 3:38:14 PM4/8/14
to scalate...@googlegroups.com
Bill, if you read my post you'll see that was my starting point.  

Nothing that site claims has been true.  I followed its instructions carefully but it's not possible to "right click on any test or collection of tests and run them".  There are no options under "Run as" when I right-click tests.  It's because of the woefully inadequate instructions on the official page that I'm looking for a tutorial.  In fact, if I manage to get this working I'll be writing one myself!

Bill Venners

unread,
Apr 8, 2014, 3:54:23 PM4/8/14
to scalate...@googlegroups.com
Hi Mark,

I would suspect there's still an issue with the directory structure. Let me take a look...

Bill

Bill Venners

unread,
Apr 8, 2014, 3:58:51 PM4/8/14
to scalate...@googlegroups.com
Hi Mark,

You still have a non-standard directory structure, and that may be confusing Eclipse. Scala projects usually organize their files in the Maven way, which is described here:

https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html

You would put your "production code" source files under:

src/main/blackjack

And those stay in package blackjack as you have them now.

Then the test files go into the test subdirectory:

src/test/blackjack

And that should go back to being in package blackjack, not blackjack.test.

Give that a shot and see if that solves your problem. As Chee Seng mentioned, this is not something related to ScalaTest but to the Scala IDE for Eclipse itself.

Bill

Mark

unread,
Apr 8, 2014, 4:12:05 PM4/8/14
to scalate...@googlegroups.com
What is the standard directory structure for using scalatest?  I didn't see anything about directory structure in the docs.

Also, I believe I've found a likely problem.  The scalatest library is definitely included in my project—I can confirm that from how adding the jar to my build configuration removed errors on the import org.scalatest.FunSuite line.  However I think there's something else that must be done from inside eclipse to install the plugin.  Under the Installing the ScalaTest Eclipse Plugin section of the page there's an image of a selection screen displayed which never came up as I went through the steps listed.  I never had the option to tick ScalaTest for Scala IDE.

I also read through the docs at https://github.com/scalatest/scalatest-eclipse-plugin and didn't see any relevant info.

Mark

unread,
Apr 8, 2014, 4:16:38 PM4/8/14
to scalate...@googlegroups.com
What's Maven?  All I want to do is get a very simple scala project running with tests.  I thought from the documentation I saw that the way would be Eclipse and its new Project feature + adding classes.  Do I need other tools?  

Is there a full tutorial that shows non Java devs how to do this anywhere?

Mark

unread,
Apr 8, 2014, 4:24:36 PM4/8/14
to scalate...@googlegroups.com

I'm getting errors from eclipse saying I'm outside the build path when I try creating and nesting folders like this.

Bill Venners

unread,
Apr 8, 2014, 4:25:17 PM4/8/14
to scalate...@googlegroups.com
HI Mark,

Yes, I think the hierarchy is still incorrect. I'm composing an email....

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

unread,
Apr 8, 2014, 4:27:00 PM4/8/14
to scalate...@googlegroups.com
Hi Mark,

Maven is a build tool for Java. It recommends a directory structure for projects, and that became the de facto standard directory structure for projects in Java, and then Scala.

One way to do this is to just create a new project with Eclipse, and then add your files to that. You should put your "production code" into src/main and your test code into src/test. People usually put the unit tests in the same package as the code under test. In your case that's package blackjack. By asking Eclipse to create a brand new project then adding files to it later, I think Eclipse should be happy.

ScalaTest itself doesn't have or require a particular directory hierarchy. Our suspicion is that Eclipse needs this. Here's what your hierarchy should look like:

Oops, sorry I think in my previous email I myself forgot the scala directory. Sorry about that. Here's what it likely wants:

src/main/scala/blackjack/Card.scala
src/main/scala/blackjack/Deck.scala
src/main/scala/blackjack/Main.scala
src/main/scala/blackjack/Player.scala
src/test/scala/blackjack/DeckSuite.scala

Give that arrangement a shot and let me know if Eclipse is happier.

Bill

Chee Seng Chua

unread,
Apr 8, 2014, 10:47:32 PM4/8/14
to scalate...@googlegroups.com
Hi Mark, 

That's weird, fixing the package should have fixed it, which I tried yesterday using fresh install of Scala IDE 3.0.3 and ScalaTest plugin.  I uploaded the sample project I used to test yesterday, you can download it here: 


after extract you can try import the project in your workspace, and see if it works for you.  Also, it would be better if you can share a sample project that reproduce your problem, so that I can have a further look to investigate the problem.

Hope this helps.

Cheers, 
Chee Seng

Mark

unread,
Apr 9, 2014, 12:27:47 AM4/9/14
to scalate...@googlegroups.com
I have a solution!  And I'm more than willing to contribute to the docs or at least write a blog post.

This was the missing step:

In Eclipse, go to Help -> Install new software
In the Work with drop-down, select Scala IDE
Options will appear under Name, check Scala IDE plugins
Click Next a couple of times, agree to the license and finish

After the Eclipse reboot, scalatest works as advertised!  Hooray!  

Bill Venners

unread,
Apr 9, 2014, 12:47:08 AM4/9/14
to scalate...@googlegroups.com
Hi Mark,

Glad to hear you have it up and running! If you have specific ideas for the docs one thing you could do is submit a pull request. The website is open source here:

https://github.com/scalatest/scalatest-website

A blog post will help as well, especially one geared towards people who are unfamiliar with Java, Maven, etc.

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.

James Moore

unread,
Apr 12, 2014, 2:27:05 PM4/12/14
to scalate...@googlegroups.com
On Tue, Apr 8, 2014 at 1:27 PM, Bill Venners <bi...@artima.com> wrote:
ScalaTest itself doesn't have or require a particular directory hierarchy. Our suspicion is that Eclipse needs this.

Traditionally, Eclipse will fail in very mysterious ways if your directory structure doesn't match your package.  So a file that defines an object in the package com.example.cupcake has to be in com/example/cupcake.  If it's not there, expect things to fail without useful error feedback anywhere.  (That's true for Java as well, but usually Eclipse will report a Java file in the "wrong" directory as a fatal error on compile.)

You could cause problems using something that looked a bit like maven's layout by putting this code:

package com.example.cupcake
class Frosting

into this file: src/main/scala/somewhere/else/Frosting.scala.

--
James Moore
ja...@restphone.com
http://blog.restphone.com/
http://www.linkedin.com/in/jamesmmooreiv
Reply all
Reply to author
Forward
0 new messages