maven emma code coverage report - spring

I am using spring 3.1.0 version api for my project and i have created the test cases for all the layer(web,service,dao).
Execute the test case using mvn test ,it working fine (ie) all the test case are getting passed.
while i am trying to get the code coverage report using mvn emma:emma getting below error.
org.springframework.beans.beanutils.instantiateclass(ljava/lang/class ljava/lang/class)ljava/lang/object
in my pom.xml
for : spring test
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>
for : emma plugin
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>emma-maven-plugin</artifactId>
<version>1.0-alpha-3</version>
</dependency>
Please share you thoughts.
Regards
Vasanth D

No need to add any plugin entry in your pom.xml, just run mvn emma:emma. You should be able to generated code coverage report successfully.

Related

How to include kotlin.test properly via Maven?

Our team is making first steps into Kotlin and I'm about to to migrate a test. I tried a first example from mockk (https://github.com/mockk/mockk/blob/master/mockk/common/src/test/kotlin/io/mockk/it/InjectMocksTest.kt). For some reason it seems I'm not able to use kotlin.test although I have added it via maven. Do I have to include any other modules? Or do I have to change something else?
(the mockk example uses Gradle so it doesn't help me).
This is what I'd like to use in my Kotlin test file but it which can't be found (at least not the packages I need):
(Restarting Intellij doesn't help, neither running mvn seperately)
This is my maven dependancy (Intellij shows now error):
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version> <!-- kotlin.version == 1.7.0 -->
<scope>test</scope>
</dependency>
The solution was (see hotkey's answer) to add the following maven dependency:
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
You need to add a dependency on one of kotlin-test-junit (for JUnit 4), kotlin-test-junit5 (for JUnit Jupiter), or kotlin-test-testng (for TestNG), depending on what test framework you are using.
The artifact kotlin-test contains only the common code, asserters and other stuff that can be reused across the frameworks.
The kotlin.test annotations like #Test or #BeforeTest are shipped in the test-framework-specific artifacts as typealiases to the actual annotations types of the test frameworks.

Issue running Kogito DMN TrafficViolationTest in my junit

I imported dmn-quarkus-example project into eclipse. the project compiles and shows no errors. when I run mvn clean quarkus:dev, I was able to test the rest endpoint through postman and it works.
but my junit in my eclipse fails with 404.
I read few blogs and updated my application.properties file with the following, still no luck
quarkus.http.port=9090
%dev.quarkus.http.port=9191
quarkus.http.test-port=8181
the other thing I had to do to get my junit working is added the following dependencies in the pom.xml
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
it working still not able to understand why?
it started working after
mvn clean install and tried maven update on eclipse.....
it random....
This sounds like Eclipse is not configured properly, in general; based on the provided information not possible to even say if it's something related to Quarkus, or just a general Eclipse configuration issue.
Moreover, tested locally with Eclipse 2019-12 and no special configuration and no special plugin, running the JUnit test works out of the box correctly, in the example screenshot below running the unit test of the REST interface for Kogito on Quarkus example:
Please ensure you have no Maven exclusion in your Eclipse configuration, and that Eclipse is allowing to run the necessary Maven phases with M2Eclipse (like running any Maven project with Eclipse)

Springboot test with coverage in Intellij

I have a spring boot 2 project with maven pom in Intellij
I thought maven uses different internal coverage tools compared to jacoco or something similar
If I click on - Run All Feature in Test with coverage
I get
Error: Could not find or load main class cucumber.api.cli.Main
If I add cucumber dependency (I dont have cucumber based tests or want it)
Exception in thread "main" cucumber.runtime.CucumberException:
No backends were found. Please make sure you have a
backend module on your CLASSPATH.
I just want to run simple spring boot rest based tests with coverage
What setup do I need?
Edit:
I had
Caused by: java.lang.ClassNotFoundException: org.jetbrains.plugins.cucumber.java.run.CucumberJvm3SMFormatter
I needed this in the pom
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.2</version>
</dependency>
and needed cucumber for java plugin installed
Now everything runs, no errors
BUT no code coverage, it is blank
It's a known issue that JUnit is not suggested from contex menu of project root: https://youtrack.jetbrains.com/issue/IDEA-198762
It appears you have the Cucumber integration installed in IDEA. This adds the option to run all feature files in the root of your project. If you want to run JUnit tests you have to drill down to src/main/test/java and select "Run All Tests".

why cucumber test results don't display examples name or steps?

I've ran into some unexpected results running a project with cucumber 2.0+. I discovered when running my tests as Junit, the immediate output doesn't display the "Examples" names or steps, instead it repeats the "Scenario outline" name for each line of "Examples" table. As practice I tried running the demo project for Screenplay pattern "TODOMVC" from https://github.com/serenity-bdd/screenplay-pattern-todomvc, using the following dependencies for cucumber
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>2.4.0</version>
<scope>test</scope>
</dependency>
I've tried executing the runner with (CucumberWithSerenity.class) as well as (Cucumber.class)
And this is how the JUNIT looks in my Ecplise.
Junit report in eclipse
Executing the runner using the old info.cukes dependencies (1.2.5) produce result with example names and steps as expected.
Just wondering if anyone else has ran into this issue, or if I'm missing something?
It looks like its intended behavior in the new cucumber version. Sort of a quick-fix solution is to add junit = "--step-notifications" in the cucumberoptions, which will display the steps, but still no luck with showing the example names.
In that case, you have add the below line of code
stepNotifications=true in your TestRunner file

Missing artifact org.glassfish.jersey.media:jaxrs-media-moxy:jar:2.16 in Maven project in Eclipse ,what to do?

I have added dependency for jersey-media-moxy in pom.xml,but I am getting
Missing artifact org.glassfish.jersey.media:jaxrs-media-moxy:jar:2.16
error message in pom.xml.
I have added necessary jar file to my build path.I have also updated the maven project using Force update ,still i am getting errors in the pom.xml.
<!-- https://mvnrepository.com/artifact/org.glassfish.jersey.media/jersey-media-moxy -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.16</version>
</dependency>
that would do the job for you!
happy coding...

Resources