Gordon Dickens is an instructor, mentor & consultant. Gordon is currently architecting and teaching several official SpringSource courses and actively tweets about open source technology at http://twitter.com/gdickens. Gordon is active within the Spring Framework community focussed on: Spring training, Spring Roo, Spring Integration, Spring Batch and Eclipse Virgo OSGi projects. Gordon is a DZone MVB and is not an employee of DZone and has posted 39 posts at DZone. You can read more from them at their website. View Full User Profile

Unit Testing Spring with Mockito & PowerMock

11.25.2011
| 4354 views |
  • submit to reddit

I’ve updated my Spring Mockito Demo app that I demonstrate when teaching with a PowerMock of a final class with a static method.

Demo Features
  • Maven 3.0
  • Maven Enforcer plugin restricting use of commons-logging, log4j, slf4j > 1.5, maven version range & java 1.6
  • All Maven plugin and java dependency versions are current and managed in properties of pom.xml
  • Maven Versions plugin for evaluating current configuration for any version updates of dependencies
    • mvn versions:display-dependency-updates scans dependencies and reports dependencies with newer versions
    • mvn versions:display-plugin-updates scans plugins and reports plugins with newer versions
    • To get the version changes w/o the ones that haven’t changed : mvn versions:display-dependency-updates | grep " -> "
  • Logback configuration with SLF4J
  • Mockito tests of the controller layer (services are mocked)
  • PowerMock configuration testing a final class with static method
  • All tests are true Unit tests, no use of Spring Context in tests, including the context creates integration tests
Code Repository

https://github.com/gordonad/core-spring-demos/tree/master/demos/mockitodemo

 

From http://gordondickens.com/wordpress/2011/10/22/unit-testing-spring-with-mockito-powermock/

Published at DZone with permission of Gordon Dickens, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: