Beyond JUnit – Testing Frameworks alternatives

JUnit is the defacto Java unit testing framework, but there’s a couple of new (and not so new) frameworks out there for web development that might be of interest. Questions you might want to ask yourself prior to adoption:

  • Are they fast and easy to develop and therefore low cost? 
  • Are they fast to run and therefore encourage adoption? 
  • Do they require maintenance and therefore engender on going cost?  
  • Can I execute them in my nightly build? 
  • Do they ultimately allow you to write more bug free code, faster?

Mockito

This is a mocking framework that makes it straight forward and fast to create mock backed tests. This reduces the cost of setting up databases and avoids writing your own. It seems the API isn’t as stable as it might be, but it has a terse and intuitive syntax.

http://mockito.org/

SureAssert

SureAssert has an annotation based mechanism for writing tests. This makes it easy to write the tests, and an Eclipse plug-in means that your incremental builds are incrementally tested.

http://www.sureassert.com/

JS Test Driver

Similar to Selenium below, this allows you the create test cases for JavaScript using a JUnit style syntax. The main caveat is that you need to factor your tests suitably for testing, and most JavaScript I’ve seen is not like that.

http://code.google.com/p/js-test-driver/

Selenium

Selenium is a top-down browsers plug in and framework that allows you to record a set of macro-like actions within a browser along with a set of assertions on those actions. E.g.

  1. Open page X. 
  2. Click button Y. 
  3. Expect text Z.

It’s nice because the tests are focussed on important scenarios (checking that pages really open and transactions actually occur), and can be exported as JUnit tests that can run as part of the nightly build. However. it’s brittle and because it depends on the app running, slow.

http://seleniumhq.org/

Reference: Beyond JUnit from our JCG partner Alex Collins at the Alex Collins ‘s blog.

Related Whitepaper:

Functional Programming in Java: Harnessing the Power of Java 8 Lambda Expressions

Get ready to program in a whole new way!

Functional Programming in Java will help you quickly get on top of the new, essential Java 8 language features and the functional style that will change and improve your code. This short, targeted book will help you make the paradigm shift from the old imperative way to a less error-prone, more elegant, and concise coding style that’s also a breeze to parallelize. You’ll explore the syntax and semantics of lambda expressions, method and constructor references, and functional interfaces. You’ll design and write applications better using the new standards in Java 8 and the JDK.

Get it Now!  

4 Responses to "Beyond JUnit – Testing Frameworks alternatives"

  1. so these frameworks are alternative to junit or complementary?

  2. Consider also TestNG (
    http://testng.org/doc/index.html ) which is a powerful testing framework that can be considered as a serious alternative for JUnit. it’s also 100% compatible with JUnit.

  3. Please do consider other mocking frameworks such as powermock and easymock.

Leave a Reply


+ nine = 16



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

20,709 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books