JUnit - Tests in Suite

JUnit - Test in Suite

Hey! In this part of the JUnit Guide we going to see how to create Tests in Suite!

Imagine that you would like to put together specific tests, that makes sense for a specific scenario.

Now imagine that you would like to run all these tests together at the same time. You can use JUnit Test in Suite.

This feature allows us to create a class that contains another classes that should be run together

Show me code!

First, we will create 2 test classes that should be tested. The first one will be the PrimeNumbersTest as you can see below

And the second one will be the FibonacciNumbersTest

Now we would like to run both tests together.

Let's create another class that will contain each one configured to be tested

Yeh, I know, just a simple class! As you may guess, we need to configure that to have all tests that will be executed

We must use 2 annotations, as you can see in the following code

Great! Now we just need to execute this class to get all the tests running. The following messages should be printed out

Awesome! Now you can have a specific context for tests that need to be executed together!

That's it!

Alexandre Gama

Alexandre Gama

Hacking Code Founder

Hacking Code Founder and Writer, Passionate Senior Software Engineer and Team Leader at @Elo7, Teacher of several courses at Caelum, Speaker at many conferences and terrible guitar player.
JUnit Tutorial - How to Configure JUnit 4 and JUnit 5 - Java Tutorial by Hacking Code

JUnit - How to Configure JUnit 4 and JUnit 5

Do you know the differences between JUnit 4 and JUnit 5 Configuration? Let's see!
JUnit Tutorial - Mastering Assertions - Java Tutorial by Hacking Code

JUnit - Mastering JUnit Assertions

Are you ready to see a lot of JUnit Examples of how to use Assertions?
JUnit Tutorial - Hamcrest Assertions - Java Tutorial by Hacking Code

JUnit - How to Use Hamcrest Assertions

Hamcrest Assertions is a great way to get your tests easier to read! Let's see how!
JUnit Tutorial - Tests in Suites - Java Tutorial by Hacking Code

JUnit - Tests in Suite

You can organize your tests in a Suite mode!
JUnit Tutorial - Test Execution Order - Java Tutorial by Hacking Code

JUnit - Test Execution Order

Do you want order your test execution? Probably it is a bed smell, but let's try it out!
JUnit Tutorial - Testing Exceptions - Java Tutorial by Hacking Code

JUnit - Testing Exceptions

Java Exceptions are in all places right? Let's deal with that with honor!


Leave a Reply

Share This
Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: