Added Spring Cloud Contract plugin and configured it for baseClassMappings
Added Spring Cloud Contract verifier
Added required base classes for generated tests
Defined groovy contract
Using Test{useunitPlatform()} to identify and execute the JUnit tests
The contract tests are getting generated in the build/generated-test-sources but not being executed. I'm getting build successful without these contract tests being executed.
I'm using gradle 7.4 version and junit-jupiter-engine version 5.7.0.
I also had this problem in the past. I however solved it in maven since my project runs with that. There might be similar configuration properties in gradle. You can manually ride the configuration and in which files to look at.
<configuration>
<contractsRepositoryUrl>http://yourContractsRepositoryUrl.com</contractsRepositoryUrl>
<!-- We want to use the JAR with contracts with the following coordinates -->
<contractDependency>
<groupId>org.example</groupId>
<artifactId>example-artifact</artifactId>
<classifier>stubs</classifier>
</contractDependency>
<!-- The JAR with contracts should be taken from Maven remote -->
<contractsMode>REMOTE</contractsMode>
<includedFiles>
<includedFile>*filennameA*</includedFile>
<includedFile>*filennameB*</includedFile>
</includedFiles>
<contractsPath>your.contracts.package.structure</contractsPath>
<baseClassForTests>
org.someservice.contracts.ContractVerifierBase
</baseClassForTests>
<basePackageForTests>org.someservice.contracts
</basePackageForTests>
<testFramework>JUNIT5</testFramework>
I hope that there is an approach in there for you. It always unpleasant to get the contracts to run in my experience :(
This issue got resolved with these changes in my case:
I added this dependency group: 'org.junit.platform', name:'junit-platform-runner', version: '1.7.0' inside testImplementation in rest/build.gradle.
useJUnitPlatform() instead of useJUnit() in test section in rest/build.gradle
Changed the #RunWith(SpringRunner.class), to #RunWith(JUnitPlatform.class) in all the BaseClasses
Replaced the #Before with #BeforeEach in all the baseclasses.
Deleting .gradle and build temporary folders and rebuilding/regenerating sources helped me
Related
spring-boot migrated from maven to gradle since 2.3.0.M1, so the question is tagged with gradle. link
What I want to do?
We known, spring-boot-dependencies project is managing lots of jar's version and works well, that's so great! We plan to use spring-boot-dependencies as a basic to manage jar's version in my company. sometimes we need to upgrade some of the jar in spring-boot-dependencies because of vulnerabilities, and this may cause version mismatch between jars.
I have noticed that, there is about 10*000 tests case in springboot project:
So I'd like to modify some jar's version in the spring-boot-dependencies project, and then run all test of spring-boot projects, to help me analyse is there any version mismatch。
What I did?
clone the latest code from github:https://github.com/spring-projects/spring-boot.git
run .\gradlew.bat build(work on windows) in the spring-boot project root directory.
it seems only a few tests get executed:
So, my question is how can I execute all test case in spring-boot project?
Any suggestions would be greatly appreciated!
the path buildSrc/ is for the gradle custom plugin code. You are therefore looking at the build tool test results.
your main code results will be under build/reports/... folder (of each module)
We migrated our maven code to gradle. When we build, we are getting error as Could not resolve all files for configuration ':***-war:compileClasspath'.
Could not find mockito-core.jar (org.mockito:mockito-core:2.8.9).
We are not referring to this jar itself.. neither we are able to locate in our code nor in pom...
How to figure out?
how to configure gradle to compile code if jar doesn't exist and pom exists in the repository or locally ?
If you can't work out where it's coming from and you don't use it at all, then you can exclude the dependency from all the configurations:
configurations.all*.exclude group: "org.mockito", module: "mockito-core"
If the dependency isn't appearing in the dependency report, then I'm somewhat at a loss as to why Gradle is complaining about it. The only other option I can think of is that some plugin is adding it in a non-standard way.
I've created a project with several gradle subprojects, including: "app" and "tests".
Tests have "app" in their dependencies. Tests use classes from "app"
When I run:
./gradlew clean test build
Everything works, tests run and pass.
But when I run:
./gradlew clean build
then the tests compilation fails with an error saying that a class is missing - in this case it's a spring-boot configuration class. I run this with --debug and it turns out that in the failing case app:bootRepackage task is executed before tests:test, the jar generated by app compilation is altered and that's why the classes cannot be found.
How can I make "./gradlew clean build" work properly?
Using: spring-boot 1.5, gradle 4.0 (and 4.1 too), io.spring.dependency-management plugin 1.0.0.RELEASE
Ideally, you shouldn't use a Spring Boot application (something that's been repackaged) as a dependency. From the documentation:
Like a war file, a Spring Boot application is not intended to be used as a dependency. If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module. The separate module can then be depended upon by your application and other projects.
If the proposed solution isn't possible in your situation, the documentation goes on to describe an alternative:
If you cannot rearrange your code as recommended above, Spring Boot’s Maven and Gradle plugins must be configured to produce a separate artifact that is suitable for use as a dependency. The executable archive cannot be used as a dependency as the executable jar format packages application classes in BOOT-INF/classes. This means that they cannot be found when the executable jar is used as a dependency.
To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as dependency.
To configure a classifier of exec … when using Gradle, the following configuration can be used:
bootRepackage {
classifier = 'exec'
}
I'm having some difficulty understanding the purpose of this plugin. Is it to modify the settings in Tomcat during the build?
I am deploying to tomcat using maven, without the plugin and it seems to work fine. Not sure if I am missing something
Cheers
Maven Tomcat plugin basically just bootstraps an embedded Tomcat container for you. Saves you the trouble of configuring an external Tomcat instance for development purposes. It can also auto-start this Tomcat instance during the build and run integration tests on it, stopping it afterwards.
If you already have a functioning workflow that you're comfortable with, no need to introduce the plugin, but it's pretty easy to configure, can run multiple web apps, can run unassembled applications etc so it's convenient to have for local development.
An even more light-weight alternative would be the Jetty plugin which starts an embedded Jetty server instead.
Maven is actually a plugin execution framework where every task is actually done by plugins.
Maven Plugins are generally used to :
create jar file
create war file
compile code files
unit testing of code
create project documentation
create project reports
A plugin generally provides a set of goals and which can be executed using following syntax:
mvn [plugin-name]:[goal-name]
For example, a Java project can be compiled with the maven-compiler-plugin's compile-goal by running following command
mvn compiler:compile
for more information go to http://www.tutorialspoint.com/maven/maven_plugins.htm
so pulgins is used to execute goals.
suppose if you don't include plugin that is required in your execution environment then it will throw an error like
A required class is missing: Lorg/apache/maven/plugin/BuildPluginManager;
so by adding appropriate plugin in pom.xml it will resolve the dependencies and execute the goal succesfully.
to remove above error just add the following plugins :
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-amps-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
</plugin>
Maven is a framework used to build JAVA applications, it provides the following
Directory Structure
Configuration Files
Build Settings
It helps in easy and structured development, primarily used for REST API Calls.
Applications built on Maven Framework, would require the same to be deployed
Its better that you get the plugin installed, since on a long run you never know what dependency may go missing
-If this helps, Mark as Answer
my junit test are passing when i am running
mvn test
but
mvn emma:emma
it has errors.
How can i find out which classes are executed?
The errors that i have are related to spring
java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;
at org.springframework.test.context.ContextLoaderUtils.resolveContextLoader(ContextLoaderUtils.java:87)
since the same config is working fine, i think that there are some problems with the classpath when i run emma.
Any advice is apreciated,
10x
Your spring-test version disagrees with your spring-beans version. Use mvn dependency:tree to find what's pulling in the relevant versions and use explicit top-level dependencies or dependency exclusions to manage them.