Paul Sprague | 22 Mar 2013 19:31
Picon

filtering tests via annotations

I've coded a patch to the maven surefire plugin which allows for filtering tests classes based on arbitrary class level annotations when using junit.

The patch is attached to the jira here: https://jira.codehaus.org/browse/SUREFIRE-833#comment-322466
There is also an example of how it works in the comments section.

I've been asked to reach out to this mailing list concerning this change. I think at issue is the question of who is responsible for this type of filtering; should this type of functionality be part of junit?

Thanks,
Paul

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
Junit-devel mailing list
Junit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/junit-devel
Luckson Karikoga | 8 Mar 2013 18:48
Picon

(no subject)

Luckson Karikoga,

Cell: +27 844 724 897 (South Africa)

------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
nicolasdascanio | 29 May 2012 23:31
Picon

xDD projects survey

If you have trouble viewing or submitting this form, you can fill it out online:
https://docs.google.com/spreadsheet/viewform?formkey=dDlpdS1Fb3pGU3Z5YTlVT28wcDZpd0E6MQ

xDD projects survey

Hi, my name is Nicolás Dascanio and i'm doing my software engenieering thesis on TDD and ATDD. My native language is not english, so I apologize for any mistake this survey may have. I'm looking for projects devoloped with xDD and i'm asking if you could take a moment of your time to fill out this survey. If you have several projects, it would be ideal to fill out the survey once for each project. However, if the answer to all the questions for every project is the same, you can fill out the survey once. ¿What do I mean with TDD? En the lifecycle starts with unit-tests -> development -> green light -> refactor (this last step may be skipped in some cycles) ¿What do I mean with ATDD? It's like TDD, but the lifecycle starts with acceptance-tests, and inside the cycle there are many TDD-cycles. It may be a big simplification, and they are not mutually exclusive, but I'm interested to know if only unit-tests were used in the sense of UTDD (unit-TDD) or if acceptance tests guided the development. The thesis will be written in Spanish, since that's my native language, but I'll do my best effort to write the conclusions (in a paper or something) in English, so everyone that helped me can read it. Thank you very much!

.form-body{display:none;}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Junit-devel mailing list
Junit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/junit-devel
Paul Hammant | 13 Mar 2012 15:38

Hamcrest Dependency

For the love of god, can you update your hamcrest dependency to 1.3.RC2



- Paul
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Junit-devel mailing list
Junit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/junit-devel
Stephen Connolly | 14 Sep 2011 11:18
Picon
Gravatar

Feature request: <at> Assumes

Consider the case where you are testing a List class...

we have

public class ListTest {

   <at> Test
  public void newListIsEmpty() {
    assertThat(new List().isEmpty(), is(true);
  }

   <at> Test
  public void newListHasSizeZero() {
    assertThat(new List().size(), is(0));
  }

   <at> Test
  public void addPutsAnElementIntoAnEmptyList() {
    List l = new List();
    l.add(new Object());
    assertThat(l.isEmpty(), is(false));
  }

   <at> Test
  public void addIncreasesSizeOfPopulatedListByOne() {
    List l = new List();
    l.add(new Object());
    int s = l.size();
    l.add(new Object());
    assertThat(l.size(), is(s + 1));
  }

}

We now want to add some tests of the delete functionality... but the
reality is that until/unless some of the preceding tests are passing,
the tests for delete are meaningless. We could have a perfectly
functional List.delete() method but until such time as the above tests
are passing, there is no way to tell that the method does not work.

Now I could code my tests like such

   <at> Test
  public void deleteIsANoOpOnEmptyList() {
    List l = new List();
    assumeThat(l.isEmpty(), is(true));
    l.delete(new Object());
  }

But all that I am doing is repeating code from the preceding tests,
having changed all those tests' assertThat(...)s into assumeThat(...)s

That does not seem agile to me, copy & paste & search & replace... ban
code smell there

I would much rather be able to annotate the tests with an  <at> Assumes
annotation that indicates that the test assumes that the specified
tests are passing, e.g.

   <at> Test
   <at> Assumes("newListIsEmpty")
  public void deleteIsANoOpOnEmptyList() {
    List l = new List();
    l.delete(new Object());
  }

   <at> Test
   <at> Assumes({"newListIsEmpty","addPutsAnElementIntoAnEmptyList")
  public void deleteRemovesAnElement() {
    List l = new List();
    Object o = new Object();
    l.add(o);
    l.delete(o);
    assertThat(l.isEmpty(), is(true));
  }

In fact in my initial example of tests, there are some additional
assumptions that I didn't make explicit

   <at> Test
   <at> Assumes("newListIsEmpty")
  public void addPutsAnElementIntoAnEmptyList() {
    ...
  }

and

   <at> Test
   <at> Assumes({"newListIsEmpty","addPutsAnElementIntoAnEmptyList")
  public void addIncreasesSizeOfPopulatedListByOne() {
    ...
  }

Now you could get some of this functionality via a TestRule...

You could watch tests to see if they pass, and skip tests annotated
with the annotation if assumed functionality is failing, but that
would result in sporadic failures of, e.g. deleteRemovesAnElement
because of the failing newListIsEmpty being executed _after_
deleteRemovesAnElement rather than before.

The simple point is that the test result of deleteRemovesAnElement is
meaningless until its assumptions are true, and while I could code the
assumptions with assumeThat(..)s C&P&S&R is even worse than C&P.

Another alternative to  <at> Assumes would be to invoke the assumed
method(s) at the start of the test, e.g.

   <at> Test
  public void deleteRemovesAnElement() {
    newListIsEmpty(); // verify assumed functionality
    addPutsAnElementIntoAnEmptyList();  // verify assumed functionality
    ...
  }

That gets rid of the C&P&S&R, but there are two issues with that:

  1. We have to manually invoke any setup/tearDown methods, including
all those of the rules that the test class has... very messy

  2. The test fails when the assumed test fails. In actuality we can
say nothing at all about whether deleteRemovesAnElement if a
newListIsEmpty is not passing... yes we could code the test
differently, but that is just moving our assumptions somewhere else.

I am sure that there are others out there who feel there is a point 3...

  3. We already ran those tests why waste time running them again?

Well the answer to 3 is that these are UNIT tests which should be very
fast, so what is the harm...

So, in my view, best practice unit testing needs the ability to mark
tests as assuming that other tests are passing, so that those tests
can be skipped when the assumptions are known to be failing or
skipped. [This is a deliberately loaded criteria... if the
org.junit.runner.Request does not include the assumed test, then that
test is neither known failing or known skipped, so we can run the test
and output a warning that the failure may be because of assumed
functionality... the use case of executing one and only one test
repeatedly until you get that test passing]

The annotation would have implications on test sorting, as any assumed
tests would have to always happen before the assuming tests (as long
as the assumed tests are in the org.junit.runner.Request)

Also might have to be two annotations, e.g.

 <at> Assumes(methodNames)
 <at> AssumesClasses(classes)

though in my view the  <at> AssumesClasses is less critical, as these are
UNIT tests and each test class should be independent to a large
extent. However I am willing to consider that some people may have
many test classes for one class under test, one test class containing
all the tests of the constructors, another testing the Add methods,
etc. in which case an  <at> AssumesClasses annotation makes sense.

Where tests contain a circular dependency, fail/error both tests

Ok, let the critique begin!

-Stephen

P.S.

I pinged Kent with an earlier version of this idea... but I think that
he missed the point about eliminating C&P&S&R that this feature would
provide because I didn't frame the idea correctly...

---------- Forwarded message ----------
From: "Kent Beck"
Date: 13 Sep 2011 17:11
Subject: Re: JUnit and test dependencies
To: "Stephen Connolly"

Stephen,

Thank you for articulating your idea so clearly. The short answer is that
no, we don't plan to support dependencies. If I have tests that are slow
enough that I care about dependencies, my most productive option is
generally to work on the design of the software until the tests are fast
enough that I no longer care. That said, my voice is only one of many. The
longer answer is that I encourage you to post your idea on the JUnit mailing
list for community discussion.

Regards,

Kent

On Sep 13, 2011, at 8:32 AM, Stephen Connolly wrote:

> Kent,
>
> Are there any plans for JUnit to support some test dependencies, such as:
>
> public class OnlyRunTestsThatMakeSenseTest {
>
>   <at> Test
>  public void basicFunctionalityWorks() {
>    ...
>  }
>
>   <at> Test
>   <at> AssumesPasses("basicFunctionalityWorks")
>  public void advancedFunctionalityWorks() {
>    ...
>  }
>
>   <at> Test
>   <at> AssumesPasses("basicFunctionalityWorks")
>  public void basicFunctionalityWorksWithBevel() {
>    ...
>  }
>
>   <at> Test
>
  <at> AssumesPasses({"basicFunctionalityWorksWithBevel","advancedFunctionalityWorks"})
>  public void advancedFunctionalityWorksWithBevel() {
>    ...
>  }
>
> }
>
> In the above example, no matter what sorting is applied,
> basicFunctionalityWorks will always be run first, and the other three
> tests will only be run if basicFunctionalityWorks passed.
>
> I see the above being completely in the spirit of unit testing, the
> point with the above is that the  <at> Before and  <at> After's will be run
> around each method, you are just saying that there is no point even
> trying to test the advanced functionality when the basic functionality
> is broken, skip those tests which we know cannot pass. That allows the
> person writing advancedFunctionalityWorks to power through the setup
> that depends on the basic functionality and not have to litter their
> advanced test with asserts that are redundant because of the basic
> functionality. Those people who are relying on side-effects should
> really, for unit tests at least, be invoking the method who's
> side-effects they depend on directly within their test method, rather
> than relying on accidental ordering.
>
> Having said that, a second feature that I think would be good is
> something like a  <at> RunAfter and/or  <at> RunBefore which would ensure that
> the test method is run in sequence even if the before or after tests
> fail/are skipped. with  <at> RunAfter and  <at> RunBefore I still think the
>  <at> Before and  <at> After methods should be invoked in-between, this would be
> moving towards more of a general purpose testing framework as opposed
> to being unit-testing focused, but JUnit is just too good ;-)
>
> Thoughts?
>
> -Stephen

------------------------------------------------------------------------------
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerry&reg; mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry&reg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
Matthew Farwell | 10 Sep 2011 22:59
Picon
Gravatar

Issue 83: Support <at> Rule/ <at> ClassRule annotation on methods as well as fields

Hello,


I came across this issue (https://github.com/KentBeck/junit/issues/83) recently, and I've created a fork & patch for it, but before I submit the pull request, I wanted to check with the development list to see if I've done the correct thing, and because this is the first contribution I've done for junit.

The problem is this: Scala does not support the creation of public fields. When you define a field with a public access modifier, this gets implemented in the bytecode as a private field with public accessors. Therefore, it is impossible to use <at> Rule annotations correctly. So, for instance, the following code throws a initializationError ("Field thrown must be public"):

import org.junit._

class ClassTest {
  <at> Rule val thrown = ExpectedException.none()

  <at> Test
  def badInt: Unit = {
    thrown.expect(classOf[NumberFormatException])
    Integer.parseInt("one")
  }
}

even though everything looks correct from the point of view of the developer (Scala fields and methods are public by default). One solution would be to allow non-public fields to be used for <at> Rule annotations, but this was rejected in (https://github.com/KentBeck/junit/issues/31). Another solution to this problem is to allow the <at> Rule annotation to apply to methods as well. So, in java, you'd have:

public class ExampleTest {
private ExpectedException thrown = ExpectedException.none();
<at> Rule
public TestRule getThrown() {
return thrown;
}

<at> Test
public void badInt() {
            thrown.expect(NumberFormatException.class);
            Integer.parseInt("one");
}
}

and Scala:

class ClassTest {
  private val vthrown = ExpectedException.none()
  <at> Rule def thrown() = vthrown

  <at> Test
  def badInt: Unit = {
    vthrown.expect(classOf[NumberFormatException])
    Integer.parseInt("one")
  }
}

To keep things consistent, <at> ClassRule is also applicable to methods.

This is the change that I've made. It is available as a branch on my fork of junit <at> github: https://github.com/matthewfarwell/junit/commit/c82458623b1dd5ed65d4f59e6f2b769f1338e13d

The main change is to BlockJUnit4ClassRunner#getTestRules() and ParentRunner#classRules(). After creating the list of TestRule from the <at> Rule annotated fields, it calls all of the <at> Rule annotated methods and adds the TestRule objects returned to the list of TestRule. This means that if a field and method are annotated with <at> Rule, then the field comes first, then the method. However, if multiple fields are defined, then the order is still undefined.

Validation for the <at> Rule annotated methods is as you would expect, the methods must be public and return a TestType. In the case of <at> ClassRule, it must also be static.

Could I please have some feedback on this: tell me if it fits in with the current direction of junit development, and if it is an acceptable feature?

I am completely open to any suggestions or criticisms of my code.

Thanks.

Matthew Farwell.

------------------------------------------------------------------------------
Malware Security Report: Protecting Your Business, Customers, and the 
Bottom Line. Protect your business and customers by understanding the 
threat from malware and how it can impact your online business. 
http://www.accelacomm.com/jaw/sfnl/114/51427462/
_______________________________________________
Junit-devel mailing list
Junit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/junit-devel
Meriem ELBOUZIDI | 1 Sep 2011 05:13
Picon

Help ! I need example of junit test with hibernate && spring

hello 
  

     I want to test my classes DAO and services using junit . I seek for tutorial or simple example 

--


EL  BOUZIDI  Meriem 
computer science engineering student (3th academic year)
National School of computer science and systems analysis (ENSIAS)
Mohammed 5th-Souissi University,
Rabat, Morocco.



------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Junit-devel mailing list
Junit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/junit-devel
David Saff | 12 Aug 2011 19:07
Gravatar

JUnit 4.9b4 (beta-)released

Hello, everyone.  We're happy to announce the release of JUnit 4.9b4.
This release's theme is Test-class and suite level Rules.  This beta
release contains a number of community-authored fixes for regression
errors in documentation and test class validation.  More information
linked from http://saffgreenbar.blogspot.com/2011/08/junit-49b4-beta-released.html,
and release notes below.  Share and enjoy, and please try it out and
give us feedback.  Thanks,

Your friendly neighborhood JUnit maintainers

## Summary of Changes in version 4.9 [unreleased!] ##

Release theme: Test-class and suite level Rules.

### ClassRule ###

The `ClassRule` annotation extends the idea of method-level Rules,
adding static fields that can affect the operation of a whole class.  Any
subclass of `ParentRunner`, including the standard `BlockJUnit4ClassRunner`
and `Suite` classes, will support `ClassRule`s.

For example, here is a test suite that connects to a server once before
all the test classes run, and disconnects after they are finished:

	 <at> RunWith(Suite.class)
	 <at> SuiteClasses({A.class, B.class, C.class})
	public class UsesExternalResource {
		public static Server myServer= new Server();
	
		 <at> ClassRule
		public static ExternalResource resource= new ExternalResource() {
			 <at> Override
			protected void before() throws Throwable {
				myServer.connect();
			};
	
			 <at> Override
			protected void after() {
				myServer.disconnect();
			};
		};
	}

### TestRule ###

In JUnit 4.9, fields that can be annotated with either ` <at> Rule` or ` <at> ClassRule`
should be of type `TestRule`.  The old `MethodRule` type, which only made sense
for method-level rules, will still work, but is deprecated.

Most built-in Rules have been moved to the new type already, in a way that
should be transparent to most users.  `TestWatchman` has been deprecated,
and replaced by `TestWatcher`, which has the same functionality, but implements
the new type.

### Maven support ###

Maven bundles have, in the past, been uploaded by kind volunteers.  Starting
with this release, the JUnit team is attempting to perform this task ourselves.

### LICENSE checked in ###

The Common Public License that JUnit is released under is now included
in the source repository.

### Bug fixes ###

- github#98: assumeTrue() does not work with expected exceptions
- github#74: Categories + Parameterized

  In JUnit 4.8.2, the Categories runner would fail to run correctly
  if any contained test class had a custom Runner with a structure
  significantly different from the built-in Runner.  With this fix,
  such classes can be assigned one or more categories at the class level,
  and will be run correctly.  Trying to assign categories to methods within
  such a class will flag an error.

- github#38: ParentRunner filters more than once

  Thanks to ` <at> reinholdfuereder`

- github#248: protected BlockJUnit4ClassRunner#rules method removed from 4.8.2
- github#187: Accidental dependency on Java 6

Thanks to ` <at> kcooney` for:

- github#163: Bad comparison failure message when using
assertEquals(String, String)
- github#227: ParentRunner now assumes that getChildren() returns a
modifiable list

### Minor changes ###

- Backed out unused folder "experimental-use-of-antunit", replaced by
  bash-based script at build_tests.sh
- Various Javadoc fixes

Thanks to ` <at> kcooney` for:

- Made MultipleFailureException public, to assist extension writers.
- github#240: Add "test" target to build.xml, for faster ant-driven testing.
- github#247: Give InitializationError a useful message

------------------------------------------------------------------------------
FREE DOWNLOAD - uberSVN with Social Coding for Subversion.
Subversion made easy with a complete admin console. Easy 
to use, easy to manage, easy to install, easy to extend. 
Get a Free download of the new open ALM Subversion platform now.
http://p.sf.net/sfu/wandisco-dev2dev
shawn smith | 14 Jul 2011 19:39
Picon
Favicon

JUnit / Ant 1.8

I am trying to get Junit 4 to run with Ant 1.8. I keep getting the same generic message when I run the build. "Could not create task or type of type : junit" I have my class path set up to access the junit jars. Anyone had similar error?

.......


<!-- JUnit properties -->

 <property name="lib" value="C:\workspaces\ABADSLocalBuild\ProjectSource\source\published\classes" />


<!-- Define the classpath which includes the junit.jar and the classes after compilling -->
     <path id="junit.class.path">           
        <fileset dir="${lib}">
            <include name="**\*.jar" />
        </fileset>   
    </path>

<target name="test" depends="package_web">
    <junit>
        <classpath refid="junit.class.path" />
        <formatter type="plain" usefile="false" />
        <test name="C:\workspaces\ABADSLocalBuild\ProjectSource\source\java\build\xyzjunWeb\com\highmark\xyzjun\test\SampleServletTest" />
    </junit>
</target>

........  

Greg
------------------------------------------------------------------------------
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
_______________________________________________
Junit-devel mailing list
Junit-devel <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/junit-devel
Behrang Saeedzadeh | 10 Jul 2011 02:38
Picon
Gravatar

Feature request: <at> Name

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.:

 <at> Test
public void headingElementShouldNotBeResolvedWithoutNamespaceMapping() {
}

 <at> Test
public void headingElementShouldBeResolvedWithNamespaceMapping() {
}

It would be nice if we could have named the test case in an annotation, e.g.:

 <at> Test
 <at> Name("Heading Element Should Not Be Resolved Without Namespace Mapping")
public void testResolution1() {
}

 <at> Test
 <at> Name("Heading Element Should Be Resolved With Namespace Mapping")
public void testResolution2() {
}

or maybe even:

 <at> Test(name = "Heading Element Should Not Be Resolve Without Namespace Mapping")
public void testResolution1() {
}

 <at> 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  <at> 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
Fran Hughes | 8 Jul 2011 17:14
Picon
Favicon

AUTO: Fran Hughes is out of the office today (returning 20/07/2011)


I am out of the office until 20/07/2011.

I will have no access to email/voice mail during this time.
If your email is regarding an existing PMR, please contact
the IBM ECM Support via contact numbers as listed in
http://www.ibm.com/planetwide.
Otherwise I will respond to your message when I return.
If you have an urgent question relating to an issue please contact
the FRC via the hotline and request to speak directly to
my Technical Manager Pick One of the following:

Hannu Lindroos (hlindroos <at> ie.ibm.com).
Douglas Good (doug.good <at> ie.ib.com).
Damien Sinardet (Damien.Sinardet <at> ie.ibm.com)

With kind regards,

Fran Hughes

Note: This is an automated response to your message  "Junit-devel Digest,
Vol 32, Issue 1" sent on 8/7/11 10:26:03.

This is the only notification you will receive while this person is away.

------------------------------------------------------------------------------
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

Gmane