Created
July 15, 2019 11:03
-
-
Save nucatus/71f1ab38d3962b2ed5801c22c235832c to your computer and use it in GitHub Desktop.
Compare assertion times
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package spcx.octopus.test; | |
| import org.assertj.core.api.Assertions; | |
| import org.junit.Test; | |
| import org.slf4j.Logger; | |
| import java.time.Instant; | |
| import static org.slf4j.LoggerFactory.getLogger; | |
| public class AssertTimeTests | |
| { | |
| private static final Logger LOG = getLogger( AssertTimeTests.class ); | |
| @Test | |
| public void assertTimeTest() | |
| { | |
| TestValues t1 = TestValues.SCREW; | |
| long startMillis = Instant.now().toEpochMilli(); | |
| Assertions.assertThat( t1 ).isEqualTo( TestValues.SCREW ); | |
| LOG.debug( "Evaluation 1 took {}ms", Instant.now().toEpochMilli() - startMillis ); | |
| startMillis = Instant.now().toEpochMilli(); | |
| Assertions.assertThat( t1 ).isEqualTo( TestValues.SCREW ); | |
| LOG.debug( "Evaluation 1bis took {}ms", Instant.now().toEpochMilli() - startMillis ); | |
| startMillis = Instant.now().toEpochMilli(); | |
| Assertions.assertThat( t1 ).isNotEqualTo( TestValues.DRIVER ); | |
| LOG.debug( "Evaluation 2 took {}ms", Instant.now().toEpochMilli() - startMillis ); | |
| startMillis = Instant.now().toEpochMilli(); | |
| assert t1 == TestValues.SCREW; | |
| LOG.debug( "Evaluation 3 took {}ms", Instant.now().toEpochMilli() - startMillis ); | |
| startMillis = Instant.now().toEpochMilli(); | |
| assert t1 != TestValues.DRIVER; | |
| LOG.debug( "Evaluation 3 took {}ms", Instant.now().toEpochMilli() - startMillis ); | |
| } | |
| enum TestValues | |
| { | |
| SCREW, DRIVER | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment