Re: [junit] how to skip a test at runtime

179 views
Skip to first unread message

Jochen Hiller

unread,
Jan 4, 2007, 5:31:16 AM1/4/07
to vietcha...@eedo.com, junite...@googlegroups.com, ju...@yahoogroups.com, Jochen Hiller
Hi Vietchau,

I've just released JUnitExt 0.2.1, which supports your enhancement request. You can now implement prerequisite callbacks also with signatures using a test description, or the className and methodName of the current test method, or a void method.

See www.junitext.org for latest information.

If you are interested about news, subscribe to "junitext-dev" at Google Groups. Bugs and enhancement requests should be posted to project home page too. See http://code.google.com/p/junitext for more information.

Much fun, Jochen


On 12/15/06, Vietchau Nguyen <vietcha...@eedo.com> wrote:

Hi Jochen,

I have added the issue to JUnitExt as you suggested for future
references... but there is no place for me to flag this as a "request"
instead of "defect"... I think there should be an option on the New
Issue page for different option (ie priority, type).

Thanks,

Vietchau

________________________________

From: ju...@yahoogroups.com [mailto: ju...@yahoogroups.com] On Behalf Of
Jochen Hiller
Sent: Friday, December 15, 2006 5:55 AM
To: ju...@yahoogroups.com
Subject: Re: [junit] how to skip a test at runtime

Hi Vietchau,

JUnitExt does only support prerequisite methods with signature
public boolean aPrereqMethod ()

Actually there is no support to forward the test name into this method.
If
this would make sense for you, could you please add an issue to
JUnitExt?
Please use issue tracking at
http://code.google.com/p/junitext/issues/list.
<http://code.google.com/p/junitext/issues/list. >

Meanwhile: David mentioned some options, writing your own startup and/or
runner, filter. From what I understand, a Filter may be appropriate for
your
requirement.

Bye, Jochen

On 12/13/06, Vietchau Nguyen <vietcha...@eedo.com
<mailto:vietchau.nguyen%40eedo.com> > wrote:
>
> Hello,
>
> I am new to JUnit and I am currently exploring the new verion, JUnit
> 4.1. I need to create unit tests for QA and they require an option to
> select which test to run at runtime. I know that there is the @Ignore
> but it need to be hard code at compile time... so I wonder if there is
> any other option in JUnit to let users specifies at runtime which
tests
> to run? I saw the extension package, which have @Prerequisite
annotation
> and will let me create a method eg. IsDBAvailable But I tried to have
> parameters to the method, eg. RunThisTest(String testName) and it
would
> not allow me to do so. .. I have too many test cases and I don't want
to
> have to write a separate function for each of them. Any suggestion on
> how to skip a test at runtime is appreciated.
>
> Thank you so much in advance,
>
> Vietchau
>
> [Non-text portions of this message have been removed]
>
>
>

[Non-text portions of this message have been removed]

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
SPONSORED LINKS
Yahoo! HotJobs

Be Discovered! ?

Upload your resume

Employers find you

New business?

Get new customers.

List your web site

in Yahoo! Search.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___

Jochen Hiller

unread,
Jan 4, 2007, 11:15:27 AM1/4/07
to Vietchau Nguyen, junite...@googlegroups.com, Jochen Hiller
Hi Vietchau,
 
see junitext-0.2.1/src/test/org/junitext/samples/SimpleTest.java:
 
--- snip here ---
package org.junitext.samples;
 
@RunWith(AnnotationRunner.class)
public class SimpleTest {
 
  @Prerequisite(requires = "doSomeTest")
  @Test
  public void testSome1() {
    assertEquals(42, 42);
  }
 
  @Prerequisite(requires = "doSomeTest")
  @Test
  public void testSome2() {
   assertEquals(42, 12);
  }
 
 /**
  * Callback with signature boolean doSomeTest(String className, String
  * methodName). Will be searched second.
  */
 public static boolean doSomeTest(String className, String testName) {
  return "testSome1".equals(testName);
 }
}
--- snip here ---
 
So: the required signature is
  public boolean aPrereqMethod (String className, String testName);
The @Prerequisite does not have to be changed: The prerequisite handler will lookup for all kinds of methods supported, according to specified ordering.
 
So, back to your request: Just change signature to have two additional parameters: className, methodName. Thats it.
 
Here, only testSome1() will executed, not testSome1().
 
I thought it should be documented in Tutorial. Needs probably more examples to clarify...
 
Bye, Jochen
 
-----Ursprüngliche Nachricht-----
Von: Vietchau Nguyen [mailto:vietcha...@eedo.com]
Gesendet: Donnerstag, 4. Januar 2007 16:49
An: Jochen Hiller
Betreff: RE: [junit] how to skip a test at runtime

Hi Jochen,

 

Thank you for such a quick response to my enhancement request. I have downloaded JUnitExt 0.2.1 but I couldn’t figure out how to use the new feature. I saw in the changeLog:

- Additional support for Prerequisite signatures
        - will first try to call "public void isXxx (Description desc)"
        - then try to call "public void isXxx(String className, String methodName)"
        - and finally fallback to "public void isXxx()"
        - see Bugfix: http://code.google.com/p/junitext/issues/detail?id=3

 

But there is no sample or tutorial on how to use this new feature. I tried to look at the .jar file but I couldn’t figure out either.

 

So, the method now should be void, instead of return a Boolean? Then how can the runner decide whether to run the test or not? Am I missing something?

 

For example, my check method is:

 

Public void runCurrentTest(String className, String methodName);

 

Then how can I call in @Prerequisite?

 

I use:

 

@Prerequisite(requires="runCurrentTest('myClassName', 'myMethodName')")

 

But it gives me an internal error when checking Prerequisite.

 

For my class, I use with:

 

@RunWith(AnnotationRunner.class)

 

I notice that the overview page mention that I should use org.junit.runner.manipulation.Filter, how do I set my program to use this, because when I use

 

@RunWith(org.junit.runner.manipulation.Filter.class)

 

the compiler complains that the class is incompatible.

 

Thank you for your help,

Vietchau


Reply all
Reply to author
Forward
0 new messages