JUnit 5 Timeouts Examples

In JUnit 5, we can use @Timeout to fail a test if the execution time exceeds a given duration. P.S Tested with JUnit 5.5.2 1. @Timeout TimeOutExample1.java package com.mkyong.timeout; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import java.util.concurrent.TimeUnit; public class TimeOutExample1 { // timed out after 5 seconds @BeforeEach @Timeout(5) void setUpDB() throws InterruptedException { //TimeUnit.SECONDS.sleep(10); …

Read more

OkHttp – How to send HTTP requests

This article shows you how to use the OkHttp library to send an HTTP GET/POST requests and some frequent used examples. P.S Tested with OkHttp 4.2.2 pom.xml <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.2.2</version> </dependency> 1. Synchronous Get Request OkHttpExample1.java package com.mkyong.http; import okhttp3.Headers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; public class OkHttpExample1 { // only …

Read more

How to configure the session timeout in servlet

The session timeout in a web application can be configurable in two ways 1) Timeout in the deployment descriptor (web.xml) – Specified the timeout value in “minute” , enclose with “session-config” element. <web-app …> <session-config> <session-timeout>20</session-timeout> </session-config> </web-app> The above setting is apply for the entire web application, and session will be kill by container …

Read more

TestNG – Timeout Test

In this tutorial, we will show you how to perform timeout test in TestNG. The “timeout” means if a unit test is taking longer than a specified number of milliseconds to finish, TestNG will abort it and market it as failed. This “timeout” can also use for performance test, to ensure the method is returned …

Read more