Home » Tag Archives: JUnit (page 4)

Tag Archives: JUnit

Using Junit Test Name

Name your tests When we create Junit test usually there is no practical use of the name of the method. The Junit runner uses reflection to discover the test methods and since version 4 you are not restricted to start the name of the method with test anymore. The name of the test methods are there for documentation purpose. There ...

Read More »

JUnit: Testing Exceptions with Java 8 and AssertJ 3.0.0

AssertJ 3.0.0 release for Java 8 makes testing exceptions much easier than before. In one of my previous blog post I described how to utilize plain Java 8 to achieve this, but with AssertJ 3.0.0 much of the code I created may be removed. Warning: this blog post contains mostly the code examples.     SUT – System Under Test ...

Read More »

Automated testing of REST-services

Despite I’m a Java and Scala developer I still passioned a lot in testing of software. If to be more precisely – web applications. It’s really interesting to develop web app and be confident that the apps have a good quality. When I’ve started a career the most popular web architecture was MVC (Model View Control) and there was pretty ...

Read More »

Nifty JUnit : Using Rule on Method and Class level

As shown in a the post Nifty JUnit : Working with temporary files, it is possible to use @Rule in a JUnit test, which is a Method level Rule. In this example I would like to show the variation of the @ClassRule for a Class level Rule. Method Rule The @Rule is fired before each test method (just like @Before) ...

Read More »

Using junit for something else

junit != unit test Junit is the Java unit testing framework. We use it for unit testing usually, but many times we use it to execute integration tests as well. The major difference is that unit tests test individual units, while integration tests test how the different classes work together. This way integration tests cover longer execution chain. This means ...

Read More »

Testing System.in and System.out with system-rules

Writing unit tests is an integral part of software development. One problem you have to solve when your class under test interacts with the operating system, is to simulate its behaviours. This can be done by using mocks instead of the real objects provided by the Java Runtime Environment (JRE). Libraries that support mocking for Java are for example mockito ...

Read More »

Separating Integration Tests from Unit Tests Using Maven Failsafe & JUnit @Category

Why Unit Tests Should Run Separately From Integration Tests TDD at the Unit Testing level is fairly straight-forward, since classes in unit testing either do not have complex dependencies, or you mock-out the dependencies with a mocking framework (ex. Mockito). However, TDD quickly becomes difficult when we get to Integration Testing. Integration Testing is basically testing a component with some or all ...

Read More »

Given When Then in Java

tl;dr you can use labels to clarify a given-when-then style of testing. What is given-when-then? given-when-then is a commonly used style of specifying system behaviour in which your tests are split into three sections. Given is the section that lays out the pre-conditions for the test, ie whatever state you’re assuming the world to be in before you start. The ...

Read More »

Testing with files and directories in JUnit with @Rule

Testing with Files and directories in JUnit is easy thanks to TemporaryFolder @Rule. In JUnit rules (@Rule) can be used as an alternative or an addition to fixture setup and cleanup methods (org.junit.Before, org.junit.After, org.junit.BeforeClass, and org.junit.AfterClass), but they are more powerful, and can be more easily shared between projects and classes. The code to be tested   public void ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns