Run All the Tests - eclipse

Is there a way to run all the tests in multiple eclipse projects?
I have a maven multi module project and want to use emma to show me code, that is not covered by any tests, not matter in which submodule it lies. So my idea is to have a single emma-coverage run, that includes all the tests of all my modules.
is there a way to do this?

You could have a look at jacoco which runs your tests in an ant/emma context and generates a report - the report component is able to merge the results from each submodule into a single report.

Related

How can I convince eclipse/JUnit4 to find all my tests, in a gradle/eclipse project?

Background
JUnit 4 test runner, within Eclipse 4.11.
I have an eclipse project that was imported from a build.gradle file. This project has several different source paths, each with their own test path.
main/java, test/java, foo/java, fooTest/java, fooTest/resource, and so on.
Problem
When I run a "whole project" JUnit configuration (debug, run, code coverage, whatever), all it finds are the tests within "test/java". I have successfully added new test classes and new #Test methods within this folder.
Tests from any other source path are ignored when I try to "Run all tests in the selected project, package, or source folder". Furthermore, selecting the specific source folder 'fooTest/java' errors out with the message "No tests found with test runner 'Junit 4'". However, when I use the "Run a single test" option with a specific test class, it finds all its test methods just fine. I can specify a particular method and the test runs just fine.
Stuff that didn't work
I tried changing the output directories of my non-main test source paths to write to the same folder as my working test source path. No joy.
I tried various settings of Eclipse's "Contains test sources" flag for my different test source paths. On or off, the behavior is the same across all my test source paths. /test/java is always found, fooTest/java is always missed. No, I haven't tried all 16 permutations of the flag across my 4 different test source paths.
I tried ripping out all the gradle-related stuff from the .project and .classpath. No change in behavior. Dammit... got my hopes up.
I tried changing the order of the <classpathentry/> in the .classpath project file. When I moved test/java such that it was no longer the first test path, I once again got the "no tests found" error, just like when I aimed the junit configuration "run all tests in the selected project, package, or source folder" at one of my other test source folders. Putting it back restored the original behavior.
Does anyone have further suggestions I could try to make my remaining tests run without individual configurations for every test class that I must manually run one at a time?
I switched to the JUnit 5 test runner, and it picked up on everything just fine. It's vintage package was able to find all my JUnit 4 tests, and I've since modified several tests to use the newfangled annotations and Assertions in JUnit 5.
Perhaps this was a known bug/limitation in the JUnit 4 runner? Ah well. It works now.

KIE Workbench Test Scenarios as a part of Maven build

In my current project we need to run Test Scenarios created in Workbench as a part of a Maven build. The final goal is to have these functional tests included to the continuous integration process.
We spent a couple of days trying to figure it out.
We opened a project that is created by Workbench in the .niogitfolder and are trying to run a maven goal.
But seems that maven goals like mvn clean install or mvn clean verify or mvn clean test don't run the Test Scenarios having a .scenario type at all.
Do you have any ideas on that?
Test scenarios are specific to kie-workbench. maven commands will not execute them during build. If you want tests to be executed during maven build then you have to write junit tests to check the execution of rules and processes.
there is currently work in progress on new version of scenarios in the kie-workbench. See the list of tasks. I would recommend you to bring this requirement there.

How do I run NetBeans JUnit tests from the command line?

I am working on a Java application project in NetBeans. I have added JUnit tests, with the #Test annotation. The tests work fine when I run them from the ‘Run Tests’ menu item.
I want to run the same tests from a command-line script. I do not know how NetBeans does this. I want a single command for testing the whole project. How can I achieve this?
Netbeans uses Ant as a build tool, and its default Ant configuration contains a number of useful targets. You can list them with the command ant -projecthelp (executed in your project directory), which should output, amongst other things,
test Run unit tests.
test-single Run single unit test.
test-single-method Run single unit test.
So, simply executing ant test will run all your unit tests on the command line. This will run the tests, write the test results to the standard output, and finish up with a brief summary (including a BUILD SUCCESSFUL message if all the tests passed, or BUILD FAILED if not).
The ant test command will return an appropriate exit code (0 if all tests passed, 1 if any failed), which can be useful -- for example, if you want to add a pre-commit hook to your version control system to forbid commits with failing unit tests.
You should build your project on the command-line with a build tool like Maven, Ant or Gradle and not rely on Netbeans for building it. Please search for this tools.
You should also consider to read a book about software development like Head First Software Development. They explain why and how to us a build tool (e.g. chapter 6 1/2 of Head First Software Development).

My jar won't add my junit tests

The contents of my jar file does not contain my junit tests. I tried creating a main class that calls my tests with "Junit Core" but that too doesn't get added to my jar file. What am I missing?
Your production package (your jar) is not supposed to contain the test code (your unit tests).
Test code is supposed to be invoked only when the tests are been executed.
You shouldn't do it, but if you want the test code to be included in your package just put it in the same root folder of your production code. Ex: if you are using Maven, your folders structure might be something like this:
project_name/src/main/java/
-> production code
project_name/src/test/java/
-> test code
In that case, change it to:
project_name/src/main/java/
-> production code
-> test code
Be aware that doing that you will have some problems, like the tests not executing during a normal build. We might help you better if you put a question asking how to accomplish your goal (what is your goal?).
Update based on the goal explained in the comments: Would be better if this tool (Silk Central) could run your tests using Maven or Ant, and I'm pretty sure it can.
I've been used different tools to run my Junit (or other XUnit frameworks) tests. What I do is to configure the tool to:
Get the source code from the version control.
Run the build/tests by calling Maven or Ant installed along the tool.
Read the Junit outputs.
Sometimes the tool has its own integration with Junit and you don't have even to use Maven or Ant.
I mean, your central build or tests tool should be able to run your tests just like you do in your own machine.
Take a look on this or search by "Silk Central junit" in the web:
http://community.microfocus.com/borland/test/silk_central/w/wiki/465.zero-maintenance-junit-testing-using-classpathsuite-in-sctm.aspx

Scala: Code coverage for projects with tests in separate modules

For a variety of admin reasons, our projects have the following structure:
someproject-core
someproject-api
someproject-test
The idea is all the tests are in a separate module.
Question: What plugin can I use to get accurate test coverage?
Use Scoverage: https://github.com/scoverage/sbt-scoverage
It supports multi-module SBT projects and measures statement coverage instead of line or branch coverages.
BTW there is a nice plugin for Sonar to browse coverage reports:
https://github.com/RadoBuransky/sonar-scoverage-plugin