You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Laird Nelson <lj...@gmail.com> on 2012/05/01 17:24:43 UTC

Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

I have a test class; let's call it TestCaseFoo.

When I run surefire:test with no value for the "test" property, this class
is found and all of its test methods execute.

I would like to run just one of those methods.

So I tried invoking Maven like this:

mvn clean test -Dtest=TestCaseFoo#testBar

...where my test case has a method like this:

@Test
public void testBar() {
  // here is where the magic happens
}

I get this error:

initializationError(org.junit.runner.manipulation.Filter)  Time elapsed:
0.004 sec  <<< ERROR!
java.lang.Exception: No tests found matching Method
testBar(com.fizbaw.TestCaseFoo) from
org.junit.internal.requests.ClassRequest@624b035d
at
org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:37)
at
org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:227)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)

Note in particular the odd method signature, or at least the output that
says testBar(com.fizbaw.TestCaseFoo).  JUnit methods must have zero
parameters.  I'm not sure what's going on here.

I am using JUnit 4.10 and Surefire 2.12.

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, May 1, 2012 at 12:36 PM, Laird Nelson <lj...@gmail.com> wrote:

> mvn clean install -fae -Pminlog -Dtest='TestCaseFoo#testBar'
>

I also tried -Dtest='TestCaseFoo#testB*' which failed with the same error,
so that told me that it was indeed able to find the name of the test
method, as the error message indicates "testBar".

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, May 1, 2012 at 5:56 PM, Stephen Connolly <
stephen.alan.connolly@gmail.com> wrote:
>
> Looks like something is going wrong alright
>

The part I don't understand is why it appears that the method description
indicates that the method takes a parameter.  I wonder if this is a problem
in JUnit 4.10 and not anything to do with Surefire?  Before I go code
spelunking, is  there an obvious place to look for where Surefire's JUnit
provider calls whatever mechanism inside JUnit that is responsible for
running the given test method?

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Stephen Connolly <st...@gmail.com>.
On 1 May 2012 22:43, Laird Nelson <lj...@gmail.com> wrote:

> On Tue, May 1, 2012 at 5:30 PM, Stephen Connolly <
> stephen.alan.connolly@gmail.com> wrote:
>
> > there is your #fail
> >
> > mvn clean install -fae -Pminlog '-Dtest=TestCaseFoo#testBar'
> >
>
> Thanks again for your prompt response.  I don't see how the quoting of the
> -Dtest= part would help, but I did it just the same, and I get the same
> error:
>
>
for reasons I have never quite understood, quoting has only ever worked for
me when the quote is at the very start of the -D, i.e. "-D or '-D


>
> mvn -o clean install '-Dtest=TestCaseFoo#testBar'
> [snip]
> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
> Running com.foobar.TestCaseFoo
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.096 sec
> <<< FAILURE!
> initializationError(org.junit.runner.manipulation.Filter)  Time elapsed:
> 0.005 sec  <<< ERROR!
> java.lang.Exception: No tests found matching Method
> testCRUD(com.foobar.TestCaseFoo) from
> org.junit.internal.requests.ClassRequest@7cf1bb78
> at
> org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:37)
>


> I'll research further.  Thanks again.  Help like yours is really quite
> valuable.
>
>
Looks like something is going wrong alright


> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, May 1, 2012 at 5:30 PM, Stephen Connolly <
stephen.alan.connolly@gmail.com> wrote:

> there is your #fail
>
> mvn clean install -fae -Pminlog '-Dtest=TestCaseFoo#testBar'
>

Thanks again for your prompt response.  I don't see how the quoting of the
-Dtest= part would help, but I did it just the same, and I get the same
error:


mvn -o clean install '-Dtest=TestCaseFoo#testBar'
[snip]
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
Running com.foobar.TestCaseFoo
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.096 sec
<<< FAILURE!
initializationError(org.junit.runner.manipulation.Filter)  Time elapsed:
0.005 sec  <<< ERROR!
java.lang.Exception: No tests found matching Method
testCRUD(com.foobar.TestCaseFoo) from
org.junit.internal.requests.ClassRequest@7cf1bb78
at
org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:37)


I'll research further.  Thanks again.  Help like yours is really quite
valuable.

Best,
Laird

--
http://about.me/lairdnelson

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Stephen Connolly <st...@gmail.com>.
On 1 May 2012 17:36, Laird Nelson <lj...@gmail.com> wrote:

> On Tue, May 1, 2012 at 12:31 PM, Stephen Connolly <
> stephen.alan.connolly@gmail.com> wrote:
>
> > you'd need to escape it with \ or quote the entire -D....
> >
>
> Yes, I am running on MacOS.  Sorry; didn't indicate that I had done that
> (single-quoted the string).  Here was the totality of my command line, in
> case there are other interactions involved:
>
> mvn clean install -fae -Pminlog -Dtest='TestCaseFoo#testBar'
>

there is your #fail

mvn clean install -fae -Pminlog '-Dtest=TestCaseFoo#testBar'


>
> (minlog is a profile that I defined that sets a few properties, nothing
> else).
>
> Thanks for your prompt and professional response.
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Laird Nelson <lj...@gmail.com>.
On Tue, May 1, 2012 at 12:31 PM, Stephen Connolly <
stephen.alan.connolly@gmail.com> wrote:

> you'd need to escape it with \ or quote the entire -D....
>

Yes, I am running on MacOS.  Sorry; didn't indicate that I had done that
(single-quoted the string).  Here was the totality of my command line, in
case there are other interactions involved:

mvn clean install -fae -Pminlog -Dtest='TestCaseFoo#testBar'

(minlog is a profile that I defined that sets a few properties, nothing
else).

Thanks for your prompt and professional response.

Best,
Laird

-- 
http://about.me/lairdnelson

Re: Surefire unable to find "bar" test method when passed -Dtest=Foo#bar

Posted by Stephen Connolly <st...@gmail.com>.
ahem...

are you running on a unix system?

you do know # is the comment start marker for most unix shells

you'd need to escape it with \ or quote the entire -D....

On 1 May 2012 16:24, Laird Nelson <lj...@gmail.com> wrote:

> I have a test class; let's call it TestCaseFoo.
>
> When I run surefire:test with no value for the "test" property, this class
> is found and all of its test methods execute.
>
> I would like to run just one of those methods.
>
> So I tried invoking Maven like this:
>
> mvn clean test -Dtest=TestCaseFoo#testBar
>
> ...where my test case has a method like this:
>
> @Test
> public void testBar() {
>  // here is where the magic happens
> }
>
> I get this error:
>
> initializationError(org.junit.runner.manipulation.Filter)  Time elapsed:
> 0.004 sec  <<< ERROR!
> java.lang.Exception: No tests found matching Method
> testBar(com.fizbaw.TestCaseFoo) from
> org.junit.internal.requests.ClassRequest@624b035d
> at
> org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:37)
> at
>
> org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:227)
> at
>
> org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:134)
> at
>
> org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:113)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
>
> org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
>
> Note in particular the odd method signature, or at least the output that
> says testBar(com.fizbaw.TestCaseFoo).  JUnit methods must have zero
> parameters.  I'm not sure what's going on here.
>
> I am using JUnit 4.10 and Surefire 2.12.
>
> Best,
> Laird
>
> --
> http://about.me/lairdnelson
>