Skip to content

Commit

Permalink
Use JUnit 5 for unit test execution (hyperledger#3620)
Browse files Browse the repository at this point in the history
Change the unit test execution to use the Junit5 JUnitPlatform. This
allows for a mix of junit 4 and junit 5 tests and for a gradual
migration to junit 5 instead of a big bang. One class depended on
junit 4 exceptions and was updated. Two tests depending on 
native libraries fail gracefully on mac (and only mac).

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
  • Loading branch information
shemnon authored and eum602 committed Nov 3, 2023
1 parent 4ebb3ea commit 688e723
Show file tree
Hide file tree
Showing 44 changed files with 250 additions and 105 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changelog

## 22.1.4
## 22.4.0-RC1

### Breaking Changes

### Additions and Improvements
- Unit tests are now executed with JUnit5 [#3620](https://github.com/hyperledger/besu/pull/3620)

## 22.1.3

Expand Down
5 changes: 4 additions & 1 deletion acceptance-tests/test-plugins/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ dependencies {
implementation 'com.google.auto.service:auto-service'
implementation 'info.picocli:picocli'

testImplementation 'org.assertj:assertj-core'
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

task testPluginsJar(type: Jar) {
Expand Down
12 changes: 7 additions & 5 deletions acceptance-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,30 @@ dependencies {
testImplementation 'io.grpc:grpc-core'
testImplementation 'io.grpc:grpc-netty'
testImplementation 'io.grpc:grpc-stub'
testImplementation 'io.jaegertracing:jaeger-client'
testImplementation 'io.jaegertracing:jaeger-proto'
testImplementation 'io.netty:netty-all'
testImplementation 'io.opentelemetry.proto:opentelemetry-proto'
testImplementation 'io.opentelemetry:opentelemetry-api'
testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp'
testImplementation 'io.opentelemetry:opentelemetry-sdk'
testImplementation 'io.opentelemetry:opentelemetry-sdk-trace'
testImplementation 'io.opentelemetry:opentelemetry-exporter-otlp'
testImplementation 'io.opentelemetry.proto:opentelemetry-proto'
testImplementation 'io.opentracing.contrib:opentracing-okhttp3'
testImplementation 'io.opentracing:opentracing-api'
testImplementation 'io.opentracing:opentracing-util'
testImplementation 'io.jaegertracing:jaeger-client'
testImplementation 'io.jaegertracing:jaeger-proto'
testImplementation 'io.vertx:vertx-core'
testImplementation 'junit:junit'
testImplementation 'org.apache.commons:commons-compress'
testImplementation 'org.apache.logging.log4j:log4j-core'
testImplementation 'org.apache.tuweni:tuweni-crypto'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.web3j:abi'
testImplementation 'org.web3j:besu'

testImplementation 'org.testcontainers:testcontainers'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

test.enabled = false
Expand Down
7 changes: 5 additions & 2 deletions besu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,19 @@ dependencies {
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(':testutil')

testImplementation 'tech.pegasys.discovery:discovery'
testImplementation 'com.google.auto.service:auto-service'
testImplementation 'com.squareup.okhttp3:okhttp'
testImplementation 'commons-io:commons-io'
testImplementation 'junit:junit'
testImplementation 'org.apache.commons:commons-text'
testImplementation 'org.apache.tuweni:tuweni-bytes'
testImplementation 'org.apache.tuweni:tuweni-units'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'commons-io:commons-io'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'tech.pegasys.discovery:discovery'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ allprojects {
systemProperty name, System.getProperty(name)
}
}
useJUnitPlatform {}
}

javadoc {
Expand Down
3 changes: 3 additions & 0 deletions config/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

configurations { testArtifacts }
3 changes: 3 additions & 0 deletions consensus/clique/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
5 changes: 4 additions & 1 deletion consensus/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

testSupportImplementation project( path: ':crypto', configuration: 'testSupportArtifacts')
testSupportImplementation project( path: ':ethereum:core', configuration: 'testSupportArtifacts')
Expand Down
5 changes: 4 additions & 1 deletion consensus/ibft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ dependencies {
integrationTestImplementation 'org.mockito:mockito-core'

testImplementation 'junit:junit'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
3 changes: 3 additions & 0 deletions consensus/ibftlegacy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
3 changes: 3 additions & 0 deletions consensus/merge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation project(':ethereum:core')

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
12 changes: 8 additions & 4 deletions consensus/qbft/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ dependencies {
integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':ethereum:core', configuration: 'testSupportArtifacts')

testImplementation 'junit:junit'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.mockito:mockito-core'
testImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
testImplementation project(path: ':config', configuration: 'testSupportArtifacts')
testImplementation project(path: ':consensus:common', configuration: 'testArtifacts')
Expand All @@ -95,6 +91,14 @@ dependencies {
testImplementation project(':metrics:core')
testImplementation project(':testutil')

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

integrationTestImplementation project(':crypto')
integrationTestImplementation project(path: ':crypto', configuration: 'testSupportArtifacts')
integrationTestImplementation project(path: ':consensus:common', configuration: 'testSupportArtifacts')
Expand Down
3 changes: 3 additions & 0 deletions container-tests/tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ dependencies {
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.testcontainers:testcontainers'
testImplementation 'org.web3j:core'
testImplementation 'org.web3j:quorum'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

test.enabled = false
Expand Down
3 changes: 3 additions & 0 deletions crypto/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

artifacts {
Expand Down
3 changes: 3 additions & 0 deletions datatypes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

configurations { testArtifacts }
Expand Down
3 changes: 3 additions & 0 deletions enclave/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

// integration test dependencies.
integrationTestImplementation project(':testutil')
Expand Down
3 changes: 3 additions & 0 deletions errorprone-checks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ dependencies {
testImplementation 'com.google.errorprone:error_prone_test_helpers'
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

epJavac 'com.google.errorprone:error_prone_check_api'
}
Expand Down
9 changes: 6 additions & 3 deletions ethereum/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ dependencies {
testResourceGeneration project(':besu')

testImplementation 'com.squareup.okhttp3:okhttp'

testImplementation 'io.vertx:vertx-auth-jwt'
testImplementation 'io.vertx:vertx-unit'
testImplementation 'io.vertx:vertx-web-client'
testImplementation 'junit:junit'
testImplementation 'org.apache.logging.log4j:log4j-core'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'io.vertx:vertx-web-client'
testImplementation 'io.vertx:vertx-auth-jwt'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

testSupportImplementation 'org.bouncycastle:bcpkix-jdk15on'

integrationTestImplementation project(':config')
Expand Down
5 changes: 4 additions & 1 deletion ethereum/blockcreation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ dependencies {
testImplementation project(':metrics:core')
testImplementation project(':testutil')

testImplementation 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'com.fasterxml.jackson.core:jackson-databind'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
3 changes: 3 additions & 0 deletions ethereum/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,11 @@ dependencies {
testImplementation 'org.apache.tuweni:tuweni-io'
testImplementation 'org.apache.tuweni:tuweni-units'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

integrationTestImplementation project(path: ':config', configuration: 'testSupportArtifacts')
integrationTestImplementation project(':testutil')

Expand Down
5 changes: 4 additions & 1 deletion ethereum/eth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ dependencies {
testImplementation project(path: ':metrics:core', configuration: 'testSupportArtifacts')
testImplementation project(':testutil')

testImplementation 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.awaitility:awaitility'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'
testImplementation 'com.fasterxml.jackson.core:jackson-databind'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'

testSupportImplementation 'junit:junit'
testSupportImplementation 'org.mockito:mockito-core'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.eth.transactions;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
Expand All @@ -27,24 +29,23 @@
import io.vertx.core.Vertx;
import org.apache.tuweni.bytes.Bytes32;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.Before;
import org.junit.ComparisonFailure;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TransactionPoolPropagationTest {
class TransactionPoolPropagationTest {

final DiscoveryConfiguration noDiscovery = DiscoveryConfiguration.create().setActive(false);

private Vertx vertx;

@Before
public void setUp() {
@BeforeEach
void setUp() {
vertx = Vertx.vertx();
}

@After
public void tearDown() {
@AfterEach
void tearDown() {
vertx.close();
}

Expand All @@ -67,8 +68,8 @@ private void wrapup(final TestNodeList txNodes) {
* 2nd order test to verify the framework correctly fails if a disconnect occurs It could have a
* more detailed exception check - more than just the class.
*/
@Test(expected = ComparisonFailure.class)
public void disconnectShouldThrow() throws Exception {
@Test
void disconnectShouldThrow() throws Exception {

try (final TestNodeList txNodes = new TestNodeList()) {
// Create & Start Nodes
Expand All @@ -80,7 +81,7 @@ public void disconnectShouldThrow() throws Exception {

node1.network.getPeers().iterator().next().disconnect(DisconnectReason.BREACH_OF_PROTOCOL);

wrapup(txNodes);
assertThatThrownBy(() -> wrapup(txNodes)).isInstanceOf(AssertionError.class);
}
}

Expand All @@ -89,7 +90,7 @@ public void disconnectShouldThrow() throws Exception {
* node. Verify that all nodes get the correct number of pending transactions.
*/
@Test
public void shouldPropagateLocalAndRemoteTransactions() throws Exception {
void shouldPropagateLocalAndRemoteTransactions() throws Exception {
try (final TestNodeList nodes = new TestNodeList()) {
// Create & Start Nodes
final TestNode node1 = nodes.create(vertx, null, null, noDiscovery);
Expand Down
3 changes: 3 additions & 0 deletions ethereum/ethstats/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}
3 changes: 3 additions & 0 deletions ethereum/evmtool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ dependencies {

testImplementation 'junit:junit'
testImplementation 'org.assertj:assertj-core'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.mockito:mockito-core'

testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
}

mainClassName = 'org.hyperledger.besu.evmtool.EvmTool'
Expand Down
Loading

0 comments on commit 688e723

Please sign in to comment.