Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Wrong JUnit test times(The execution times shown on JUnit view are wrongly computed because of setup times)
Wrong JUnit test times [message #1822080] Wed, 26 February 2020 22:56
Theo Alves  Monteiro is currently offline Theo Alves MonteiroFriend
Messages: 1
Registered: February 2020
Junior Member
I noticed the test times are wrong and get very confuse because of setup times. Let's call setup times the time spent on things like @Extension, @BeforeAll, @AfterEach. With @Nested classes this is even more confuse.

For instance, the follow test suite:



import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

class EclipseTimes {

	@BeforeAll
	static void setUpBeforeClass() throws Exception {
		System.out.println("@ static void uthils.EclipseTimes.setUpBeforeClass() throws Exception");
		TimeUnit.SECONDS.sleep(3);
	}

	@AfterAll
	static void tearDownAfterClass() throws Exception {
		System.out.println("@ static void uthils.EclipseTimes.tearDownAfterClass() throws Exception");
		TimeUnit.SECONDS.sleep(2);
	}

	@BeforeEach
	void setUp() throws Exception {
		System.out.println("@ void uthils.EclipseTimes.setUp() throws Exception");
		TimeUnit.SECONDS.sleep(4);
	}

	@AfterEach
	void tearDown() throws Exception {
		System.out.println("@ void uthils.EclipseTimes.tearDown() throws Exception");
		TimeUnit.SECONDS.sleep(1);
	}

	@Test
	void test() throws Exception {
		System.out.println("@ void uthils.EclipseTimes.test() throws Exception");
		TimeUnit.SECONDS.sleep(5);
	}
	
	@Nested
	public class FirstNested {
		
		@BeforeEach
		void setUp() throws Exception {
			System.out.println("@ void uthils.EclipseTimes.FirstNested.setUp() throws Exception");
			TimeUnit.SECONDS.sleep(4);
		}

		@AfterEach
		void tearDown() throws Exception {
			System.out.println("@ void uthils.EclipseTimes.FirstNested.tearDown() throws Exception");
			TimeUnit.SECONDS.sleep(1);
		}

		@Test
		void test() throws Exception {
			System.out.println("@ void uthils.EclipseTimes.FirstNested.test() throws Exception");
			TimeUnit.SECONDS.sleep(5);
		}
		
	}
	
	@Nested
	public class SecondNested {
		
		@BeforeEach
		void setUp() throws Exception {
			System.out.println("@ void uthils.EclipseTimes.SecondNested.setUp() throws Exception");
			TimeUnit.SECONDS.sleep(2);
		}

		@AfterEach
		void tearDown() throws Exception {
			System.out.println("@ void uthils.EclipseTimes.SecondNested.tearDown() throws Exception");
			TimeUnit.SECONDS.sleep(3);
		}

		@Test
		void test() throws Exception {
			System.out.println("@ void uthils.EclipseTimes.SecondNested.test() throws Exception");
			TimeUnit.SECONDS.sleep(5);
		}
		
	}

}



The execution of this suite gave the result on the screenshot attached:
index.php/fa/37467/0/

I would expect that any @Test method would report only 5 seconds, but it aggregates setups and cleanup times. Shouldn't these setup/cleanup times only be added on the test class?

Previous Topic:Serial port
Next Topic:Validation - how to exclude certain files?
Goto Forum:
  


Current Time: Tue Nov 05 03:45:19 GMT 2024

Powered by FUDForum. Page generated in 0.02909 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top