How to see code coverage of Spock tests in Eclipse - java

I am working on a Java project in Eclipse. I use Spock to test my code.
My project contains two directories:
a src directory containing all my Java files
a test directory containing all my Spock tests
I don't use any automation build system.
How can I see the code coverage of my Spock tests?

The Spock runner is based on the JUnit runner.
So you do exactly the same as you do with JUnit
Go to Menu Help -> Eclipse Marketplace
Search for Eclemma Install it and restart Eclipse (after accepting
licence)
Right click on any Spock test (or directly)
Select from the menu Coverage as..-> JUnit test
Wait a while and a Coverage window will appear. Enjoy!\
More details are in the official site http://www.eclemma.org/installation.html

Related

How to run JUnit tests from the command line instead of Intellij IDEA?

I have an Intellij IDEA project with Junit5 tests in the tests folder. The tests works if I click on the play button using IDEA's GUI. However, I need to be able to use the command line to run those tests but I don't know how.
Given the project folder how can I use the command line to run the tests in the tests folder without relying on IDEA's GUI?
You can use the JUnit ConsoleLauncher:
The ConsoleLauncher is a command-line Java application that lets you launch the JUnit Platform from the console. For example, it can be used to run JUnit Vintage and JUnit Jupiter tests and print test execution results to the console.
To run all tests from a package you can run:
java -jar junit-platform-console-standalone-1.5.2.jar
-cp 'build/classes/java/test'
--select-package com.mypackage
You can read the tutorial from MKyong for an introduction: JUnit 5 ConsoleLauncher examples
Most build systems provide test targets. For example:
Gradle: ./gradlew test
Maven: mvn test

Generate separate coverage reports for tests using Jacoco or IntelliJ IDEA

I have a Java application set up on IntelliJ IDEA. I have several tests for which I need to generate coverage reports individually for each of the tests.
IntelliJ IDEA coverage runner runs all the tests at once and generates a single report showing the overall coverage. How can I use IntelliJ IDEA coverage runner or Jacoco plugin in gradle script to generate separate reports the tests?
Run tests separately one by one (see How to run only one test class on gradle), for each run use separate directory to save report.

Run Gradle test and not Junit test in IntelliJ IDEA 15 when choosing configuration type to run with

I updated to Intellij 15.02 from 14 and wanted to run my tests using Gradle not JUnit, but I'm not getting the options anymore like the image you see here.
I want to be able to choose configuration type.
The thing that is happening now when I run a test is that it runs it as a JUnit test by default.
I have imported the gradle project with gradle by selecting the gradle file in the project.
I have deleted each configuration entry at the top so everything is clean and empty when running a new test with Spock.
My current "fix" is to manually create a new config entry for the gradle test. Intellij is not intelligent enough to create that same Junit test as a Gralde test.
I'm confused.
I found the solution.
They have changed the way you select this option in the new version of intellij 15.02.
You have to select Gradle Test Runner.
Please take a look:
In modern versions of IntelliJ (I have Ultimate 2019.2.3) here's what you need to update:
Update from "Gradle" to "IntelliJ IDEA"

How to configure Testng eclipse plugin with arquillian

I have arquillian set up here with some integration tests, but so far I'm running them with:
mvn clean test -Parq-jbossas-managed
I would like to run and see the errors/successes on the Testng eclipse plugin. How do I do that?
I have tried to add a testng running config, selection a class to test, but it didn't work.
Any ideas?
Running TestNG from its Eclipse plugin or from maven are two different things!
The TestNG Eclipse plugin comes with its own version of TestNG - afaik, this isn't possible (without starting eclipse processes from you build process)
If reporting matters to you, you should have a look at ReportNG
To start a test run with your Eclipse Plugin (so you can see it in Eclipse's dedicated view), you have to select your test-class (or your test-xml) and use Run As -> TestNG test.

How to get Hudson to show complete selenium report?

Our Hudson installation shows a very spartan version of the Selenium report:
Selenium Report Result
numTestPasses 2
numTestFailures 0
I've understood that it should be possible to view full reports via Hudson, and also track development of the tests. But how?
We configured Hudson to run Selenium through an Ant task. Then we added a post-build action to "Publish JUnit test result report." With this setup we can see each failed test name along with how long each test took and the ability to drill down into all the tests to see specifics.
You may be able to just add that post build action to your project using the Selenium plugin.
Not sure if this fits in your environment: I'm running selenium-rc via JUnit (and phpunit) test cases using ant in a Hudson freestyle Project.
Hudson collects and publishes JUnit and via xUnit Plugin various other test results in an optional post build step.
Maybe you just need to find out where the build process stores the actual xml report and instruct hudson to publish it?
I run Selenium tests in Hudson using this plugin. It runs my Selenium tests and publishes detailed test reports. Very easy to configure, maybe not perfect if you have a lot of test suites to execute.
We use the SeleniumHQ plugin. The results are saved in the workspace (this is done in the project config by using "Publish Selenium Report"). You can save the build reports by using "Archive the artifacts" in project config.
We have written the Selenium tests as normal JUnit tests, which gets executed with the rest of the tests, so the reports are embeded i the junit test report generated by hudson.

Categories