[groovy-user] JUnit4 and "No runnable methods"

825 views
Skip to first unread message

Dave Syer

unread,
Jan 14, 2008, 2:40:54 AM1/14/08
to us...@groovy.codehaus.org

I get an initialisation error from the test runner when I try and run a
JUnit4 test case like in the examples online
(http://groovy.codehaus.org/Using+JUnit+4+with+Groovy) - "No runnable
methods". I have imported org.junit.Test and put @Test on one of the
methods.

(What the online example didn't mention was that you can't use the same name
for the test case class as its filename - in that case I get a "Duplicate
class definition" error. I guess that is expected?)

Stack trace:

JUnit version 4.4
.E
Time: 0.016
There was 1 failure:
1) initializationError0(test.ArrayUtilTestCase)
java.lang.Exception: No runnable methods
at
org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:32)
at
org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:43)
at
org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:36)
at
org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:27)

--
View this message in context: http://www.nabble.com/JUnit4-and-%22No-runnable-methods%22-tp14796532p14796532.html
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Ford Guo

unread,
Dec 21, 2008, 3:32:29 AM12/21/08
to us...@groovy.codehaus.org


Dave Syer wrote:
>
> I get an initialisation error from the test runner when I try and run a
> JUnit4 test case like in the examples online
> (http://groovy.codehaus.org/Using+JUnit+4+with+Groovy) - "No runnable
> methods". I have imported org.junit.Test and put @Test on one of the
> methods.
>
> (What the online example didn't mention was that you can't use the same
> name for the test case class as its filename - in that case I get a
> "Duplicate class definition" error. I guess that is expected?)
>
> Stack trace:
>
> JUnit version 4.4
> .E
> Time: 0.016
> There was 1 failure:
> 1) initializationError0(test.ArrayUtilTestCase)
> java.lang.Exception: No runnable methods
> at
> org.junit.internal.runners.MethodValidator.validateInstanceMethods(MethodValidator.java:32)
> at
> org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:43)
> at
> org.junit.internal.runners.JUnit4ClassRunner.validate(JUnit4ClassRunner.java:36)
> at
> org.junit.internal.runners.JUnit4ClassRunner.<init>(JUnit4ClassRunner.java:27)
>
>

I have the same error,there is any options?
--
View this message in context: http://www.nabble.com/JUnit4-and-%22No-runnable-methods%22-tp14796532p21113104.html


Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Jochen Theodorou

unread,
Dec 21, 2008, 8:06:56 AM12/21/08
to us...@groovy.codehaus.org
pfew... this thread was started nearly a year ago...

if you have the same problem could you please first do the following
things: tell us which version of Groovy you use. And give us please a
simple testcase, that reproduces the problem.

then we can tell much more

bye blackdrag


--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

ghq7613

unread,
Dec 21, 2008, 8:40:45 PM12/21/08
to us...@groovy.codehaus.org
I use testng now,it works.And I use JUnit4's error env:
JDK1.6
groovy1.5.7,
junit4.4,and use annotation.

I hope it is useful.


Jochen Theodorou wrote:
> pfew... this thread was started nearly a year ago...
>
> if you have the same problem could you please first do the following
> things: tell us which version of Groovy you use. And give us please a
> simple testcase, that reproduces the problem.
>
> then we can tell much more
>
> bye blackdrag
>
>

SophosGuy

unread,
Jan 7, 2009, 10:10:50 AM1/7/09
to us...@groovy.codehaus.org

I am still having the same issue environment is....

JUnit 4.5
Groovy 1.5.6

Test case is

import org.junit.Test
public class MathTest {
@Test public void firstTest(){
println("Test")
}
}

I use maven and Intellij to try it both give me the same No runnable Method
error

--
View this message in context: http://www.nabble.com/JUnit4-and-%22No-runnable-methods%22-tp14796532p21333168.html


Sent from the groovy - user mailing list archive at Nabble.com.

SophosGuy

unread,
Jan 7, 2009, 10:20:46 AM1/7/09
to us...@groovy.codehaus.org

Never mind apparently you need an Assert.* (except fail) in order to get it
to work

--
View this message in context: http://www.nabble.com/JUnit4-and-%22No-runnable-methods%22-tp14796532p21333384.html

Vaclav Pech

unread,
Jan 7, 2009, 10:32:06 AM1/7/09
to us...@groovy.codehaus.org
Hello folks,

I'm experimenting with Groovy mixins and hit a wall with the following
scenario. I'm sure I'm doing something wrong and hope that you might be
able to tell me the way out.

class A {

def final foo() {
bar()
}

private final String bar() {
return "Bar"
}
}

class B extends A {}

class C {}

C.metaClass {
mixin B
}

def c= new C()
c.foo()


Running the script results in "Caught:
groovy.lang.MissingMethodException: No signature of method: C.bar() is
applicable for argument types: () values: {}". Changing the bar's
visibility to non-private or mixing in A instead of B helps here.
I assume the problem is that bar() is not directly visible in B, but
since I'm calling bar() from foo(), which is defined in A, I would
expect the code to work.
Am I right that calling private methods (bar) from inherited mixed-in
methods (foo) is not possible?

Vaclav

Jochen Theodorou

unread,
Jan 7, 2009, 11:16:09 AM1/7/09
to us...@groovy.codehaus.org
Vaclav Pech schrieb:

> Hello folks,
>
> I'm experimenting with Groovy mixins and hit a wall with the following
> scenario. I'm sure I'm doing something wrong and hope that you might be
> able to tell me the way out.
>
> class A {
>
> def final foo() {
> bar()
> }
>
> private final String bar() {
> return "Bar"
> }
> }
>
> class B extends A {}
>
> class C {}
>
> C.metaClass {
> mixin B
> }
>
> def c= new C()
> c.foo()
>
>
> Running the script results in "Caught:
> groovy.lang.MissingMethodException: No signature of method: C.bar() is
> applicable for argument types: () values: {}". Changing the bar's
> visibility to non-private or mixing in A instead of B helps here.

I would say this is a bug. If mixing in A works, then mixing in B should
work too.

> I assume the problem is that bar() is not directly visible in B, but
> since I'm calling bar() from foo(), which is defined in A, I would
> expect the code to work.

I guess the implementation is doing nasty things with "this"

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

Alex Tkachman

unread,
Jan 7, 2009, 11:23:22 AM1/7/09
to us...@groovy.codehaus.org
Please submit JIRA

Vaclav Pech

unread,
Jan 7, 2009, 11:36:02 AM1/7/09
to us...@groovy.codehaus.org
Thank you guys for clarification.
Created http://jira.codehaus.org/browse/GROOVY-3266

Alex Tkachman

unread,
Jan 8, 2009, 10:16:54 AM1/8/09
to us...@groovy.codehaus.org
Fixed in the trunk

Vaclav Pech

unread,
Jan 8, 2009, 2:35:58 PM1/8/09
to us...@groovy.codehaus.org
Hello,

here's one more little issue that puzzled my head. It might be somewhat
related to http://jira.codehaus.org/browse/GROOVY-3266.

class Parent {
private String myPrivateProperty="secret"

public final void foo() {
[1, 2, 3].each {
println myPrivateProperty
}
}
}

class Child extends Parent {}

new Child().foo()

This script throws:
Caught: groovy.lang.MissingPropertyException: No such property:
myPrivateProperty for class: Child

Changing visibility of myPrivateProperty to non-private or instantiating
Parent instead of Child makes the script run just fine. I wonder whether
this behavior is intentional or not.

Regards,

Jochen Theodorou

unread,
Jan 9, 2009, 6:32:29 AM1/9/09
to us...@groovy.codehaus.org
Vaclav Pech schrieb:

> Hello,
>
> here's one more little issue that puzzled my head. It might be somewhat
> related to http://jira.codehaus.org/browse/GROOVY-3266.
>
> class Parent {
> private String myPrivateProperty="secret"
>
> public final void foo() {
> [1, 2, 3].each {
> println myPrivateProperty
> }
> }
> }
>
> class Child extends Parent {}
>
> new Child().foo()
>
> This script throws:
> Caught: groovy.lang.MissingPropertyException: No such property:
> myPrivateProperty for class: Child
>
> Changing visibility of myPrivateProperty to non-private or instantiating
> Parent instead of Child makes the script run just fine. I wonder whether
> this behavior is intentional or not.


It is a bug, it is already reported and it is an annoying thing. It is
not intended to work like this. A workaround is:

public final void foo() {
def x = myPrivateProperty
[1, 2, 3].each {
println x
}
}

but of course that does not satisfy all needs.

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/

Alex Tkachman

unread,
Jan 9, 2009, 7:18:01 AM1/9/09
to us...@groovy.codehaus.org
I don't think it is related to http://jira.codehaus.org/browse/GROOVY-3266.

Jochen, do you think so?

Vaclav Pech

unread,
Jan 9, 2009, 7:40:12 AM1/9/09
to us...@groovy.codehaus.org
Sorry for misleading you guys, I'm not familiar enough with the codebase
to be able to back my statement here.
From the user's perspective both issues are related to indirect access
to a private member from a subclass and that's where the similarity
might well end.

Vaclav

Vaclav Pech

unread,
Jan 9, 2009, 7:41:53 AM1/9/09
to us...@groovy.codehaus.org
Hello Jochen,

thank you for clarification as well as for the workaround. That should
help in my case.

Vaclav


Jochen Theodorou wrote:
>
> It is a bug, it is already reported and it is an annoying thing. It is
> not intended to work like this. A workaround is:
>
> public final void foo() {
> def x = myPrivateProperty
> [1, 2, 3].each {
> println x
> }
> }
>
> but of course that does not satisfy all needs.
>
> bye blackdrag
>

Vaclav Pech

unread,
Jan 9, 2009, 7:42:46 AM1/9/09
to us...@groovy.codehaus.org
Thank you Alex, much appreciated.

Vaclav

Jochen Theodorou

unread,
Jan 9, 2009, 7:47:55 AM1/9/09
to us...@groovy.codehaus.org
Alex Tkachman schrieb:

> I don't think it is related to http://jira.codehaus.org/browse/GROOVY-3266.

I didnt look at the issue, but no, I don't think it is related

Reply all
Reply to author
Forward
0 new messages