Home » Tag Archives: JUnit (page 8)

Tag Archives: JUnit

JUnit Pass Test Case on Failures

junit-logo

Why create a mechanism to expect a test failure? There comes a time when one would want and expect a JUnit @Test case fail. Though this is pretty rare, it happens. I had the need to detect when a JUnit Test fails and then, if expected, to pass instead of fail. The specific case was that I was testing a ...

Read More »

Test Driven Traps, part 2

junit-logo

The Story of a Unit in Unit Tests In the previous part of this article, you could see some bad, though popular, test samples. But I’m not a professional critic (also known as a troll, or a hater), to grumble about without having anything constructive to say. Years of TDD have taught me more than just how bad the things ...

Read More »

Spring Testing Support and Context caching

spring-interview-questions-answers

Spring provides a comprehensive support for unit and integration testing – through annotations to load up a Spring application context, integrate with unit testing frameworks like JUnit and TestNG. Since loading up a large application context for every test takes time, Spring intelligently caches the application context for a test suite – typically when we execute tests for a project, ...

Read More »

Using PowerMock to Mock Constructors

powermock-logo

In my opinion, one of the main benefits of dependency injection is that you can inject mock and/or stub objects into your code in order to improve testability, increase test coverage and write better and more meaningful tests. There are those times, however, when you come across some legacy code that doesn’t use dependency injection and held together by composition ...

Read More »

5 Tips for Unit Testing Threaded Code

junit-logo

Here’s a few tips on how take make testing your code for logical correctness (as opposed to multi-threaded correctness). I find that there are essentially two stereotypical patterns with threaded code: Task orientated – many, short running, homogeneous tasks, often run within the Java 5 executor framework, Process orientated – few, long running, heterogeneous tasks, often event based (waiting on ...

Read More »

Tips for testing with Java

junit-logo

Introduction I love automated testing. In a rare diversion into op-ed1 I thought a put few thoughts (read – opinions) together. Before I start on how best to compose your tests, I briefly ask – What are the reasons for testing? Broadly, I think they are: Reduce total number of bugs / increase product stability Ensure software works as per ...

Read More »

Spring Integration – Session 2 – More Hello Worlds

spring-interview-questions-answers

This is a follow up to Spring Integration Session 1 The first session was a simple Hello World application using Spring Integration. I want to take it a little further by considering a few more scenarios around it. So the first change to the Hello World application is to add in a Gateway component. To quickly revisit the earlier test ...

Read More »

JUnit, Logback, Maven with Spring 3

logback-logo

In this series we have already learnt to set up a basic Spring MVC application and learnt how to handle forms in Spring MVC. Now it is time to take on some more involved topics. However, before we venture into deeper waters, let’s get some basics set up. Unit testing I am no TDD evangelist. There I said it. I ...

Read More »

Categorize tests to reduce build time

apache-maven-logo

Before we progress with the main content of the article, let’s get a few definitions out of the way. Unit tests Unit tests are tests that are small (tests one use case or unit), run in memory (do not interact with database, message queues etc.), repeatable and fast. For our conversation let us restrict these to JUnit based test cases ...

Read More »

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 »
Do you want to know how to develop your skillset and become a ...

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!
Get ready to Rock!
To download the books, please verify your email address by following the instructions found on the email we just sent you.

THANK YOU!

Close