question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.NoSuchMethodError for latest java8 junit5 when using both consumer and provider in project

See original GitHub issue

Expected behavior -> When running junit5 using the latest Pact version for java 8 in IDE, be able to run the consumer and provider tests (separate run for each) as well as on the command line (using mvn and only including the requisite test classes).

Actual behavior -> Running the test using the IDE or mvn produces the following error:

[ERROR] test_full_consumer_for_event{List}  Time elapsed: 0.033 s  <<< ERROR!
java.lang.NoSuchMethodError: au.com.dius.pact.core.support.expressions.ExpressionParser.parseExpression$default(Ljava/lang/String;Lau/com/dius/pact/core/support/expressions/DataType;Lau/com/dius/pact/core/support/expressions/ValueResolver;ZILjava/lang/Object;)Ljava/lang/Object;

When I exclude the dependency au.com.dius.pact.core:support then I am able to run the consumer test (but, obviously not the provider tests)

Versions used:

<dependency>
	<groupId>au.com.dius.pact.consumer</groupId>
	<artifactId>junit5</artifactId>
	<version>4.1.28</version>
	<scope>test</scope>
</dependency>
<dependency><!-- Added to allow for the LambdaDsl configuration -->
	<groupId>au.com.dius</groupId>
	<artifactId>pact-jvm-consumer-java8</artifactId>
	<version>4.0.10</version>
	<scope>test</scope>
</dependency>
<dependency>
	<groupId>au.com.dius.pact.provider</groupId>
	<artifactId>junit5</artifactId>
	<version>4.1.28</version>
	<scope>test</scope>
</dependency>

Looking at the code changes, it appears the class and method that’s missing the expected argument is in the ExpressionParser.kt.

Link to the change: https://github.com/pact-foundation/pact-jvm/commit/d3f49648c064ace5e95334ffe6faa6088ec812e9#diff-60f5a5b831e279e4b778ce72ce319289d154ab60ec3535191a0737371c817c8d

Please let me know how to be able to run both consumer and provider tests (I’m doing Async validation if that helps) in the same project.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
RHervey-ebcommented, Oct 29, 2021

Thanks so much for a quick response.

If I do that, is there another place where I can get the ability to use the Lambda Dsl which is indeed much easier to manage/read?

I’m referring to this: https://docs.pact.io/implementation_guides/jvm/consumer#a-lambda-dsl-for-pact

0reactions
RHervey-ebcommented, Nov 8, 2021

The solution was simple, the needed dependencies list that worked is: (turns out the dependency artifact and group being off was the culprit) 😃

		<dependency>
			<groupId>au.com.dius.pact.consumer</groupId>
			<artifactId>junit5</artifactId>
			<version>4.1.28</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>au.com.dius.pact.consumer</groupId>
			<artifactId>java8</artifactId>
			<version>4.1.28</version>
		</dependency>
		<dependency>
			<groupId>au.com.dius.pact.provider</groupId>
			<artifactId>junit5</artifactId>
			<version>4.1.28</version>
			<scope>test</scope>
		</dependency>
Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoSuchMethodError for latest java8 junit5 when ...
Expected behavior -> When running junit5 using the latest Pact version for java 8 in IDE, be able to run the consumer and...
Read more >
Fixing the NoSuchMethodError JUnit Error | Baeldung
This situation may occur, for example, when the project's JUnit version is different from the one that is used in a Maven or...
Read more >
java.lang.NoSuchMethodError: org.junit.platform.commons.util ...
I am trying to run test case with JUnit 5.5.1. Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.discovery.
Read more >
How to Fix java.lang.NoSuchMethodError in Java - Rollbar
A java.lang.NoSuchMethodError is a runtime error which occurs when a method is called that exists at compile time, but does not exist at ......
Read more >
JUnit 5 User Guide
JUnit 5 requires Java 8 (or higher) at runtime. However, you can still test code that has been compiled with previous versions of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found