Skip to content

Instantly share code, notes, and snippets.

@nucatus
Created July 15, 2019 11:03
Show Gist options
  • Select an option

  • Save nucatus/71f1ab38d3962b2ed5801c22c235832c to your computer and use it in GitHub Desktop.

Select an option

Save nucatus/71f1ab38d3962b2ed5801c22c235832c to your computer and use it in GitHub Desktop.
Compare assertion times
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