Effective Unit Testing for Java EE
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
.travis.yml
LICENSE
README.md
pom.xml

README.md

Build Status Maven Central

Need(le) for Speed - Effective Unit Testing for Java EE

@NeedleProject

Needle4j is a lightweight framework for testing Java EE components outside of the container in isolation. It reduces the test setup code by analysing dependencies and automatic injection of mock objects. It will thus maximize the speed of development as well as the execution of unit tests.

Needle Coffee Cups

Core Features:

  • Instantiation of @ObjectUnderTest Components

  • Constructor, Method and Field based dependency injection

  • Injection of Mock objects by default

  • Extensible by providing custom injection providers

  • Wiring of object graphs

  • Database testing via JPA Provider, e.g. EclipseLink or Hibernate

  • EntityManager creation and injection

  • Execute optional database operations during test setup and tear down

  • Transaction Utilities

  • Provide Utilities for Reflection, e.g. for private method invocation or field access

  • Needle can be used with JUnit or TestNG.

  • It supports EasyMock and Mockito out-of-the-box.

Getting started

Add the following dependencies to your pom.xml file to get started using Needle:

<dependency>
    <groupId>org.needle4j</groupId>
    <artifactId>needle4j</artifactId>
    <version>2.3</version>
    <scope>test</scope>
</dependency>

(plus junit, mockito, ...)

Implementing your first Needle Test:

public class UserDaoTest {

    @Rule
    public DatabaseRule databaseRule = new DatabaseRule();

    @Rule
    public NeedleRule needleRule = new NeedleRule(databaseRule);

    @ObjectUnderTest
    private UserDao userDao;

    @Test
    public void testFindByUsername() throws Exception {
        final User user = new UserTestdataBuilder(
        databaseRule.getEntityManager()).buildAndSave();

        User userFromDb =
            userDao.findBy(user.getUsername(), user.getPassword());

        Assert.assertEquals(user.getId(), userFromDb.getId());
    }
}

For the documentation and more examples please refer to the maven site.

Licensing

Needle is licensed under GNU Lesser General Public License (LGPL) version 2.1 or later.

Needle URLs

<script type="text/javascript" src="http://www.ohloh.net/p/714248/widgets/project_thin_badge.js"> </script>

Release Nodes

Version 2.2 - https://github.com/akquinet/needle/issues?milestone=1&state=closed

Previous Versions - https://github.com/akquinet/needle/blob/master/src/docs/dist/changelog.txt