Groovy JUnit test support

Good news everyone!

I've implemented support for the Groovy JUnit tests which basically means you can finally use Groovy in the area where is so highly productive! You can create a new Groovy JUnit test in the New File/Groovy/Groovy JUnit test and it should behave in the same way as for Java tests. Which means if there is no JUnit setup in your project yet, you can choose between JUnit 3 and JUnit 4 template and with respect to your choice the project settings will be changed (in case of the Maven based projects the correct dependencies and plugins are added to the pom.xml and in case of the Ant based project the JUnit dependency is configured). Or if the project is already configured, the correct template will be used. After that the test skeleton is created and you can write your own code and of course run the tests together with the java ones.

Some of you were asking for this feature and of course I don't expect it will be perfect from the beginning so I would be really glad to see some constructive feedback about what could be improved and/or redesigned ;] ..at the end I have to say that the feature is not active for the Ant based Java EE projects yet (I'm aware of it and it will be fixed to the NetBeans 7.3 final - actually it will be done in a few days/weeks, just want you to know). But it's already complete in all types of the Maven based projects and also for the Ant based J2SE projects.

And as always, the daily build where you can try the feature can be downloaded right here, so don't hesitate to try it!

Comments:

I have a Netbeans Grails project, in 7.3 Beta, with a mix of Java. It would be nice to be able to include the java in the unit testing, but I can't get a testcase created for the java. And if I craft one in Groovy, it does not get run in the testing.

Is there a way to do this?

Posted by guest on October 18, 2012 at 06:42 AM PDT #

I'm sorry, but I don't understand the problem. What do you mean by "I can't get a testcase created for the java"? There is a wizard called "New JUnit test" which creates java test case. And you should be able to create Java test case and Groovy test case and they will be run together. If it's not possible then it looks like a bug, but I would need more concrete information. Thanks!

Posted by Martin Janicek on October 19, 2012 at 01:49 AM PDT #

I have tried a few things, between a Java Project, and a Grails Project.

1. Create a new Java Class Library project. (File | New Project | Java | Java Class Library)
a) Create a new TestClass in the Source Packages (Select project, File | New File | Java | Java Class)
b) Create a new JUnit test. (Select class, right Click | Tools | Create Tests)
or
c) Create a new JUnit test. (Select Project, File | New File | Unit Tests | Test for Existing Class)

2. Create a new Groovy/Grails project (File | New Project | Groovy | Grails Application)
a) Create a new Java Class (Select Project | File | New File | Java | Java Class)
b) Try to create a new JUnit test. (Select class, right Click | Tools). There is no Create Tests popup item.
or
c) Create a new JUnit test. (Select Project, File | New File | Unit Tests).
1) There is no Unit Tests item.
2) You can select Groovy, and Groovy JUnit Test, but if you select Java, there is no JUnit)

So I can't get into a New JUnit test Wizard, for a Java class, while in a Grails project.
I can create a JUnit test, for a Java class, of whole cloth, in the Grails project's test/unit folder, and it will run, but I can't seem to find a wizard to do it, for a Java class, in a Grails project.

Posted by guest on October 20, 2012 at 06:28 AM PDT #

Ok, I can see your problem now. I'm going to create new bugzilla ticket for this so we will be able to track it. Thanks for your help!

Posted by Martin Janicek on October 22, 2012 at 07:09 AM PDT #

Hello Martin,

I just installed Netbeans 7.4, and I was excited to try groovy junit support.
After installing Netbeans from the platform-independent zip, I added the Groovy & Grails plugin via Tools > Plugins

My Netbeans Project has two root test directories:
test/java
test/groovy

I use Junit 4+
If I right-click on a .groovy test file in the editor, the Test File menu entry is disabled.
Same result if I click on the same file in the Project Window

I was hoping that I could treat .groovy files that are in a test directory, just like I do .java files in a test directory (I mean I right click >> Test File *all the time*),but it seems not.
Is this a bug?

Posted by thurston on November 09, 2013 at 01:33 PM PST #

Hi thurston, yes this sounds like a bug, because it was working correctly earlier for sure. Could you please file a new issue in NetBeans bugzilla and attach your project with it? It works for me even now, but I'm trying only the simplest use case ever (creating new project, creating new groovy JUnit test and right click in the file).. so maybe it's caused by some internal configuration in your project. I would like to help you, but need to have your project (or some steps how to reproduce it) first. Thanks ;)

Posted by Martin Janicek on November 11, 2013 at 02:12 AM PST #

Hello Martin,

It would be difficult to attach my entire project, but I will try to setup a simple project with a similar project structure and see if I can reproduce it.
Just to be clear though, I'm not sure what you mean when you write "create new groovy JUnit test" - I'm using JUnit 4, and so I just do:
New > Groovy Class . . .

The only thing that makes it a "test" class is that it is located in test/groovy (which is defined as a test package folder in the project properties) and that it has junit @Test annotations (there is not even a naming convention of the classes); this approach definitely works for Java "test" classes, I'm presuming it should work for .groovy classes as well?

Anyways, I'll try to setup a simpler project and submit that as an issue, presuming it should work

Posted by thurston on November 13, 2013 at 08:10 AM PST #

OK, so I just tried it with:
New > Groovy JUnit Test . . . (which I think is new to Netbeans 7.4?) and the same problem persists; so that sure sounds like a bug; I will create a simple project and file an issue; I do select JUnit 4.x in the "Select JUnit version" dialog that comes up.

I think the key is that the IDE needs to recognize that any .groovy file that is in a *test package folder* (as defined in project properties) should have its Test File context menu enabled and working. This is how it works for plain .java files and has for awhile

Posted by thurston on November 13, 2013 at 08:24 AM PST #

This is working usually but maybe your project configuration is somehow different than mine. Definitely file an issue and I'll take a look at it!

Posted by Martin Janicek on November 13, 2013 at 08:28 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the Groovy support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today