Re: Feature request: @Name

David Saff <[email protected]> Fri, 15 Jul 2011 12:52:26 -0500
Newsgroups gmane.comp.java.junit.devel
Message-ID <CACj8BuOXTrFKyJ3UzLt8+M6kVJF3ZOTmnXzPrYkOX6xBOy-G4Q@mail.gmail.com>
Behrang,

Sorry for the long response delay.  This is an interesting idea.  You
should be able to try it out fairly easily:

1) Create your own subclass of BlockJUnit4ClassRunner that overrides
describeChild
2) Annotate your classes with @RunWith(MyRunner.class)

One thing to watch out for is whether your running infrastructure
(ant, maven, eclipse, etc.) is robust against spaces in test
descriptions.  If it works out for you, let's think about contributing
it to junit.contrib.  Thanks,

   David Saff

On Sat, Jul 9, 2011 at 7:38 PM, Behrang Saeedzadeh <[email protected]> wrote:
> Hi,
>
> I think it would be nice if there was an annotation for JUnit for
> naming annotations.
>
> Right now creating test cases with self explanatory names lead very
> long and ugly methods names, e.g.:
>
> @Test
> public void headingElementShouldNotBeResolvedWithoutNamespaceMapping() {
> }
>
> @Test
> public void headingElementShouldBeResolvedWithNamespaceMapping() {
> }
>
> It would be nice if we could have named the test case in an annotation, e.g.:
>
> @Test
> @Name("Heading Element Should Not Be Resolved Without Namespace Mapping")
> public void testResolution1() {
> }
>
> @Test
> @Name("Heading Element Should Be Resolved With Namespace Mapping")
> public void testResolution2() {
> }
>
> or maybe even:
>
> @Test(name = "Heading Element Should Not Be Resolve Without Namespace Mapping")
> public void testResolution1() {
> }
>
> @Test(name = "Heading Element Should Be Resolved With Namespace Mapping")
> public void testResolution2() {
> }
>
> Right now I have started using a similar annotation for my new
> projects, but had it been integrated with JUnit, it would have used
> the name in reporting errors, etc.
>
> A @Description element might also be useful for providing more details
> about a test.
>
> Cheers,
> Behrang Saeedzadeh
> http://www.behrang.org
>
> ------------------------------------------------------------------------------
> All of the data generated in your IT infrastructure is seriously valuable.
> Why? It contains a definitive record of application performance, security
> threats, fraudulent activity, and more. Splunk takes this data and makes
> sense of it. IT sense. And common sense.
> http://p.sf.net/sfu/splunk-d2d-c2
> _______________________________________________
> Junit-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/junit-devel
>

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev