IntelliJ runs unit tests with Maven instead of JUnit - maven

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

Related

Maven how to show Junit test like on Eclipse IDE

I would like to run Junit tests via maven command like having the test result
with the same graphical message that I can see using Eclipse IDE.
For example, if I run Junit test via Eclipse I can see this tree image:
But, if I run the same tests via maven command line, I can see only the grand total result without details.
For example:
There is a way to run maven command line tests and receive the test result like Eclipse IDE?
I use surefire plugin on my project.
Thanks in advance.

IntelliJ Gradle project, no test runner tab

I try the spock test framework with IntelliJ (2021.3.2), created the demo from https://blog.jetbrains.com/idea/2021/01/tutorial-spock-part-1-getting-started/ with the first simple test.
I don't see the test runner tab (even if I could run the tests). The Gradle configuration is set by default to run tests by using Gradle. If I switch the Gradle configuration to run tests using IntelliJ IDEA, I got the test runner tab.
How could I get the test runner tab with Gradle too?

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 configure build step for maven goal in teamcity to run unit test

I use junit in my java project (developed using intellij idea) for unit test, and I want to configure build step in team city to run my unit tests only. I also use maven to build my project. It works when I set goals for maven to "clean compile" but I dont know how to configure build step to run unit tests.
Also in command line. when i run "maven test" it runs unit tests correctly and shows the failures.
I can't comment on TeamCity, but I'll try to help anyway out of my maven knowledge.
So first of all mvn clean compile will never run your unit tests, because maven has a concept of lifecycle and testing phase is coming after compile phase.
When you run mvn test it will run all the face up to (including) the test phase so the unit tests will run as a part of maven default lifecycle.
Now you're asking about a "build step for running unit tests" from which I conclude that you need a separate step. In maven phase is nothing more than running a series of plugins. In maven plugin has goals, so you can run a plugin responsible for running unit tests directly.
In maven this plugin is called "surefire" and a goal is called "test", so you can run:
mvn surefire:test
Given the classes (production code and tests) are compiled, you will see that this only runs your unit tests. So this probably has to be configured in Team City.

Exclude testng tests while building in jenkins

I have a test which consists of both junit test and testng tests. It works fine when i run 'mvn test' from parent pom, but testng tests fail while building in jenkins. I need a way to skip testng tests from running in jenkins.
You said you use jenkins so i assume that you are using maven plugin :
Have you tried to skip test cases in your Maven run? Use the code below in maven properties section of maven plugin:
maven.test.failure.ignore=true
Or
please use below code in properties section of maven plugin to skip the test cases
skipTests=true
Hope this helps
It's better to set it up via runtime in Jenkins' job configuration:
Invoke Top Level Maven -> Advanced.
Add maven.test.skip=true
Once the tests are OK, just remove this line.
You can disable test execution in runtime as well:
mvn -Dmaven.test.skip=true

Resources