Home » Tag Archives: JUnit (page 9)

Tag Archives: JUnit

Tomcat Context JUnit @Rule

junit-logo

A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring context for integration tests. import org.apache.commons.dbcp.BasicDataSource; import org.apache.log4j.Logger; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import javax.xml.parsers.DocumentBuilder; import ...

Read More »

Moving Beyond Core Hamcrest in JUnit

hamcrest-logo

In the post Improving On assertEquals with JUnit and Hamcrest I introduced use of Hamcrest with JUnit. I then looked at JUnit’s Built-in Hamcrest Core Matcher Support. In this post, I look at how to apply Hamcrest’s non-core matchers with JUnit. These non-core matchers are NOT included with JUnit by default, but are available by including a Hamcrest JAR in ...

Read More »

JUnit’s Built-in Hamcrest Core Matcher Support

junit-logo

In the post Improving On assertEquals with JUnit and Hamcrest, I briefly discussed Hamcrest “core” matchers being “baked in” with modern versions of JUnit. In that post, I focused particularly on use of JUnit’s assertThat(T, Matcher) static method coupled with the Hamcrest core is() matcher that is automatically included in later versions of JUnit. In this post, I look at ...

Read More »

JUnit and Hamcrest: Improving On assertEquals

hamcrest-logo

In my blog post Are Static Imports Becoming Increasingly Accepted in Java?, I discussed the increasing use of static imports in Java to make code more fluent in certain contexts. Unit testing in Java has been particularly affected by the static import and in this blog post I provide one quick example of using static imports to make more fluent ...

Read More »

Beyond JUnit – Testing Frameworks alternatives

selenium-logo

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

Read More »

Covering your tests with Cobertura, JUnit, HSQLDB, JPA

hypersql-logo

Hello, how are you? Let us talk today about a very useful tool named “Cobertura”. This framework has the same functions of the Emma framework that we saw in another post. The major difference between Cobertura and Emma is that Cobertura displays the resume page with graphics. If you want to see the other topics about this subject click on ...

Read More »

Effective Unit Testing – Not All Code is Created Equal

junit-logo

Unit Testing is one of the most adopted methodologies for high quality code. Its contribution to a more stable, independent and documented code is well proven . Unit test code is considered and handled as an a integral part of your repository, and as such requires development and maintenance. However, developers often encounter a situation where the resources invested in ...

Read More »

7 mistakes of software testing

junit-logo

Though most developers know the importance of testing, it seems that a lot of them still aren’t testing enough. And if they write tests, they test just test wrong. UNIT TESTS If some tests are written in applications, most of them will be unit tests. It’s easy to test a utility class by just calling all utility methods, passing some ...

Read More »

TestNG or JUnit

junit-logo

For many years now, I have always found myself going back to TestNG whenever it comes to doing Unit Testing with Java Code. Everytime, I picked up TestNG, people have asked me why do I go over to TestNG especially with JUnit is provided by the default development environment like Eclipse or Maven. Continuing the same battle, yesterday I started ...

Read More »

DB unit testing with dbUnit, JSON, HSQLDB and JUnit Rules

dbunit-logo

In this week’s run of my TDD course, I thought it would be interesting to write a little fixture to make it easier to use dbUnit. My original thought was just to teach dbUnit about JSON, but it turns out that Lieven Doclo has done that already. So I decided to go a step further and also combine dbUnit with ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.