How to set up cucumber with Main class and maven build - maven

I have made a project from where I intent to run integration tests using docker: https://github.com/navikt/bidrag-cucumber-nais
In this project, I have
a kotlin application called IntegrationTests.kt
a pom.xml which makes maven build the application
I would like to
only run cucumber tests from the application: IntegrationTests.kt
only run unit tests from maven
Issues I do not understand:
from IntelliJ: when running junit tests, it will run cucumber and "regular" junit tests (this is expected behaviour)
from IntelliJ: when running the application, IntegrationTests.kt, cucumber tests are run (this is expected behaviour)
from maven: I have two profiles which eirher run junit-jupiter (by default) or junit-vintage (cucumber tests from cli). The profile running junit-vintage will not discover any tests... (?)
from console: I cannot run the executable jar which are build... (?)

from IntelliJ: when running junit tests, it will run cucumber and "regular" junit tests
IDEA has runners for both JUnit 4 and JUnit 5. They're enabled when you have either one on the class path.
from maven: only junit tests with cucumber is run (junit vs junit-jupiter?)
Maven only enables one runner at a time, either JUnit 4 or JUnit 5 and defaults to the more modern version when multiple are present. You are using cucumber-junit which is a JUnit 4 integration. Consider adding junit-vintage in addition to junit-jupiter. That way JUnit 5 can run JUnit 4 tests or consider using junit-platform-engine.

Related

How to visualize output of JUnit integration tests in IntelliJ when using docker-maven-plugin?

IntelliJ has a nice integration with JUnit that allows me to run some or all of my unit tests and visualize the results of each test and test class with a collapsible/expandable hierarchy that even takes into account JUnit5 nested test classes. I can click on any failed test to see the log output from running just that method. It looks like this:
I have now defined an integration test phase to my project using two popular Maven plugins:
maven-failsafe-plugin separates my JUnit tests into two phases. The test classes ending in "Test" run during the test phase, and those ending in "IT" run during the integration-test phase.
fabric8's docker-maven-plugin which I'm using to spin up a test database in the pre-integration-test phase and shut it down in the post-integration-test phase.
I can tell IntelliJ to run a Maven command (such as maven clean verify) that runs this lifecycle and tells me if the tests have passed. However, a Maven "run configuration" in IntelliJ doesn't produce the same helpful output. All I get is the success or failure status of each phase, and I can navigate to the console output for a phase, but not an individual test. The output looks like this:
So here's my question: Is there any way to configure IntelliJ (or Maven, or both) to give that hierarchical test-by-test output while keeping the Maven lifecycle I've defined, with the temporary use of a docker-container database for my integration tests?
I know that I can manually spin up the test database container, use IntelliJ's JUnit runner for my integration tests, and then manually stop the container. Can I do better?
Unfortunately there is no tool to show test-by-test output while keeping the Maven lifecycle as Maven run configuration is used in this case. Please use Junit run configuration for Class/method output in test runner tab.

How to skip cucumber tests during build & deployment when unit test runs but after deployment it should run cucumber tests via Jenkins - Maven

I have a build project in which i implemented Cucumber BDD and wrote features file and test classes. Now, what i want is that during build & deployment in Jenkins pipeline, all Unit tests should get executed but not the Cucumber tests i.e. Integration tests. As soon as deployment is completed then these cucumber tests should get executed. How we can achieve that?
Is there any way to skip cucumber test during the deployment but after the deployment completion it should execute them?
You can tag your tests with annotations as #Deploy and #AfterDeploy,
To maven deployment script, you can add following script :
-Dcucumber.options="--tags #Deploy"
For the tests after deployment you can use following :
-Dcucumber.options="--tags #AfterDeploy"

Maven Verify Starting and Stopping the Spring Test Runner on Each class

I am having a Spring Boot application with around ~500 Tests (Unit and mostly Integration).
When i start running the tests in IntelliJ with second click -> Run all Tests - tests run in around 10-15mins.
When i try to run the tests with "mvn verify -P itest" in IntelliJ terminal, the execution time is around an hour. This is because this command starts and stops the Spring Test Runner Server on every class (which is not my desired result).
The IntelliJ second click -> Run all Tests starts it only once.
Our Jenkins Job is running the tests with "mvn verify -P itest", so my question is how can i change this behavior, to start and stop the Test Runner only once (with this "mvn verify -P itest" command).
itest is the profile that we have in our pom.xml which includes the classes that contain integration tests (using maven failsafe plugin)
Here are the annotations of our base abstract Integration Test class
#RunWith(SpringJUnit4ClassRunner.class)
#SpringBootTest(classes = MainApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
I found this article which could by similar to my problem, but this does not explain the behavior that IntelliJ gives me.
Reset Spring-Boot During Integration Tests
Thanks a lot in advance
I found out why this was happening. There was a setting in my pom file which stated
'reuseForks' maven failsafe property to be false.
I changed it to be true and now it is working fine.
Intellij works in the same way - it is reusing the forks for all the tests.
Read More
http://maven.apache.org/surefire-archives/surefire-2.17/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html

Configure cucumber in TeamCity to run unit tests only using tags (Maven)

I have both unit and acceptance tests in a maven project (spring boot). I would like to run unit tests only when my build runs in TeamCity. I am using cucumber.
When i run the tests via command line, everything works as expected (only unit tests are run)
c:\apache-maven-3.3.9\bin\mvn package -Dcucumber.options="--tags #unit"
However, in teamcity, all tests are being run (unit and acceptance). It seems teamcity ignores my cucumber.options
In addition, when I double click on the 'test' lifecycle in Intellij, all tests are run as well (not just unit tests) So my guess is that TeamCity is doing exactly what the 'test' lifecycle does.
How can i get around this problem (in TeamCity)?. I have tried using a 'Command line' step, which works, however, i lose all the tests reporting as well as test coverage reports.
i have solved the Intellij problem by creating (or changing) a configuration:
Try writing it this way in TeamCity:
"-Dcucumber.options= --tags #unit"

IntelliJ runs unit tests with Maven instead of JUnit

I have some Unit tests, that when I try to run, it automatically creates Maven run/debug configuration, instead of JUnit (the integrated IDEA tab).
For some tests it does use JUnit run\debug configuration and manually - I can create both Maven and JUnit.
How do I make JUnit to be the default test runner ?
The problems is that I had maven runner plugin installed, causing all my tests to run with Maven
You can use the maven option "-Dskip=true" to suppress the maven test execution, and you can add your own test configuration to the build process. This screenshot was taken form IntelliJ 15.0.2.
Update: maven option

Resources