Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Software Testing with JUnit 5

You're reading from   Mastering Software Testing with JUnit 5 Comprehensive guide to develop high quality Java applications

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781787285736
Length 350 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Boni Garcia Boni Garcia
Author Profile Icon Boni Garcia
Boni Garcia
Arrow right icon
View More author details
Toc

Conditional test execution

In order to establish custom conditions for test execution, we need to use the JUnit 5 extension model (introduced in Chapter 2, What's new in JUnit 5, in the section The extension model of JUnit 5). Concretely, we need to use the conditional extension point called ExecutionCondition. This extension can be used to deactivate either all tests in a class or individual tests.

We are going to see a working example in which we create a custom annotation to disable tests based on the operative system. First of all, we create a custom utility enumeration to select one operative system (WINDOWS, MAC, LINUX, and OTHER):

package io.github.bonigarcia;

public enum Os {
WINDOWS, MAC, LINUX, OTHER;

public static Os determine() {
Os out = OTHER;
String myOs = System.getProperty("os.name").toLowerCase();
if (myOs.contains...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime