Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate servicetalk-client-api tests from jUnit4 to jUnit5 #1612

Merged
merged 6 commits into from
Jun 14, 2021

Conversation

amitvc
Copy link
Contributor

@amitvc amitvc commented Jun 10, 2021

Motivation:

JUnit 5 leverages features from Java 8 or later, such as lambda functions, making tests more powerful and easier to maintain.
JUnit 5 has added some very useful new features for describing, organizing, and executing tests. For instance, tests get better display names and can be organized hierarchically.
JUnit 5 is organized into multiple libraries, so only the features you need are imported into your project. With build systems such as Maven and Gradle, including the right libraries is easy.
JUnit 5 can use more than one extension at a time, which JUnit 4 could not (only one runner could be used at a time). This means you can easily combine the Spring extension with other extensions (such as your own custom extension).
Modifications:

Unit tests have been migrated from JUnit 4 to JUnit 5
Result:
successfully ran ./gradlew :servicetalk-client-api:build
Module servicetalk-client-api now runs tests using JUnit 5

@amitvc amitvc mentioned this pull request Jun 11, 2021
44 tasks
@idelpivnitskiy idelpivnitskiy changed the title Changes to upgrade to junit 5 for servicetalk-client-api module Migrate servicetalk-client-api tests from jUnit4 to jUnit5 Jun 11, 2021
@@ -1,5 +1,5 @@
/*
* Copyright © 2018, 2020 Apple Inc. and the ServiceTalk project authors
* Copyright © 2018, 2021 Apple Inc. and the ServiceTalk project authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change to 2018, 2020-2021

testImplementation "junit:junit:$junitVersion"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit5Version"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junit5Version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5Version"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mind moving this to the end of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

Copy link
Contributor

@tkountis tkountis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, some np comments and good to go

@amitvc
Copy link
Contributor Author

amitvc commented Jun 14, 2021

@tkountis Thanks for the review. I have made the changes.

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @amitvc!

@@ -1,5 +1,5 @@
/*
* Copyright © 2019 Apple Inc. and the ServiceTalk project authors
* Copyright © 2021 Apple Inc. and the ServiceTalk project authors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright © 2021 Apple Inc. and the ServiceTalk project authors
* Copyright © 2019, 2021 Apple Inc. and the ServiceTalk project authors

@@ -1,5 +1,5 @@
/*
* Copyright © 2018 Apple Inc. and the ServiceTalk project authors
* Copyright © 2021 Apple Inc. and the ServiceTalk project authors
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Copyright © 2021 Apple Inc. and the ServiceTalk project authors
* Copyright © 2018, 2021 Apple Inc. and the ServiceTalk project authors

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, you can skip updating copyright headers (we planning to automate this task) or use ./scripts/update-copyright.sh main and that script will update everything correctly.

Comment on lines 76 to 79
Exception e = assertThrows(ExecutionException.class, () -> {
cf.newConnection("c1", null).toFuture().get();
cf.newConnection("c2", null).toFuture().get();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first newConnection invocation is not expected to throw:

Suggested change
Exception e = assertThrows(ExecutionException.class, () -> {
cf.newConnection("c1", null).toFuture().get();
cf.newConnection("c2", null).toFuture().get();
});
cf.newConnection("c1", null).toFuture().get();
Exception e = assertThrows(ExecutionException.class, () -> cf.newConnection("c2", null).toFuture().get());

Comment on lines 35 to 37
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5Version"
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion"
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future PRs, please place testRuntimeOnly dependency after all testImplementation dependencies. We try to sort by the scope first:

Suggested change
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5Version"
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion"
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion"
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit5Version"

@idelpivnitskiy
Copy link
Member

@amitvc I will apply my suggestions. Please take a look at them and keep in mind for future PRs ❤️

@idelpivnitskiy idelpivnitskiy merged commit 6384f04 into apple:main Jun 14, 2021
@amitvc
Copy link
Contributor Author

amitvc commented Jun 14, 2021

@idelpivnitskiy Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants