Pitest mutation testing execute over kotlin files only - java

I arrived to a legacy project where multiple files are developed in Java and many others in Kotlin. I have be able to configure Pitest to execute the mutation test and i have a correct report.
Now I would like to execute the mutation test only over the Kotlin files.
I tried to use the <targetClasses> but the param expresion is able to include certain packages, but I didn't discover a way to include certain types of files only.
I also tried to use the <excludedClasses> to add there a Java identificator that exclude this type of files, but again it doesn't work.
Do you know a way to use the targetClasses or the excludedClasses to let the kotlin files only in the scope of the Pitest execution?
Thank you in advance.

There is no built in way to limit mutation to only kotlin files. You would need to implement an mutation interceptor.
https://pitest.org/quickstart/advanced/
Or use the exclusions functionality provided by the arcmutate extentions to ignore files with a .java extension.
https://docs.arcmutate.com/docs/exclusions.html

Related

How to glue multiple steps directories to a cucumber test in Intellij?

I have a Cucumber scenario whose steps are defined in multiple Step files, as opposed to only having only one. If I decide to run the test using Intellij I go to run/debug configurations menu and the form provides a field named glue which enables me to specify the steps package.
So far I was able to run the scenarios that have all steps defined in the same Steps file, but I was unable to figure out how to do it for the scenarios that require multiple steps files located in different packages. I've tried a csv approach but without success. Does anyone know what I am missing? Thank you for your help.
There are few ways to configure the glue paths with Cucumber.
As a cucumber.properties file in the root package (usually src/test/resources/cucumber.properties):
cucumber.glue=com.example.steps1,com.example.steps2
Via the command line
--glue com.example.steps1 --glue com.example.steps2
Or with the #CucumberOptions annotation.
#RunWith(Cucumber.class)
#CucumberOptions(glue ={"com.example.steps1", "com.example.steps2"})
public class RunCucumberTest {
}
When using IDEA you have to separate the glue packages with a new line or space (not a comma!).
com.example.steps1
com.example.steps2
And if you are on a recent version of Cucumber (6+) you don't have to provide the glue at all. Cucumber will search the class path by default.
M.P. Korstanje's answer provides very useful tips but not for this specific case. What worked for me was:
Specify the parent package as opposed to several distinct sub-packages (e.g. use only com.example instead of both com.example.steps1, com.example.steps2) in the Glue field
Select the correct module in the Use classpath of module field.

Building an eclipse plugin. What dependency and which class could I extend to implement warning signs in Java and Effective pom files for a project?

I am a bit new to eclipse plugin development. My requirement:
I want to show warning signs(like screenshot attached) in the import statements Java files and effective pom files of Java projects based on some parameters.
Assuming eclipse already has some classes and functions for this, I would like to know what dependencies I could add in my Manifest file of my Eclipse Plugin and which class I could extend and functions I could use to implement my requirement?
Any help would be very much appreciated. Thank you.
If you're willing this to happen at same time as compilation, you can add an extension to the org.eclipse.jdt.core.compilationParticipant extension point ( https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fextension-points%2Forg_eclipse_jdt_core_compilationParticipant.html ) and implement the CompilationParticipant.reconcile() method to look at the content of the file and use putProblems() to add problems.
You can also put it in a separate builder ( https://help.eclipse.org/2019-12/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-5.htm ), or resource listener, or document listener, that would invoke file.createMarker(...) to add the error markers.
All that depends on which layer you prefer to hook onto.

How can Junit test classes detect classes defined in a kotlin file?

I have a Java gradle project in which i'm using a kotlin file to easily define pojo-like classes on one line. However, when i try to start a junit5 test I get a compile error stating that it can't detect any of the classes defined in the kotlin file. I have the kotlin plugin included in the gradle.build file. How do i get the test classes to detect the classes defined in the kotlin file?
Thank you
If you write JUnit5-tests with Gradle, be sure to have something like the following in place in your build.gradle-(or build.gradle.kts)-file, so that Gradle also knows that it should use the JUnit5-platform (compare also JUnit 5 User Guide - Build support - Gradle):
tasks.withType<Test> {
useJUnitPlatform()
}
Moreover also ensure that the annotation you use is the following:
org.junit.jupiter.api.Test
and not the one of JUnit4, i.e. org.junit.Test. If you have that one, you probably want to remove the junit4-dependency altogether.

Running Clover coverage reporter inserts new column to CSV test and breaks build

I am trying to integrate Clover with a Java project at work. Clover has been added to the classpath, the plugin has been added to the POM and the license has been set up.
When I run mvn clean clover:setup test clover:aggregate clover:clover Clover starts up correctly. However, tests that generate csv's fail because the CSV output is not what is expected. This is what gets generated for one of the tests:
<ID,NAME,[__CLR4_1_2_TEST_NAME_SNIFFER,"DESCRIPTION,Long","DESCRIPTION,Short",country
001,Fred,com_atlassian_clover.TestNameSniffer$1#e628ccb,Mr. Fred Flinstone,Fred Flinstone,US
002,Bob,com_atlassian_clover.TestNameSniffer$1#e628ccb,Mr. Bob the builder,Bob the builder,UK
003,Tintin,com_atlassian_clover.TestNameSniffer$1#e628ccb,Mr. Tin Tin,Tin Tin,FR
004,,com_atlassian_clover.TestNameSniffer$1#e628ccb,,Rob the Bob,
005,,com_atlassian_clover.TestNameSniffer$1#e628ccb],,Tom the Bob,
>
This is what is expected:
<ID,NAME,["DESCRIPTION,Long","DESCRIPTION,Short",country
001,Fred,Mr. Fred Flinstone,Fred Flinstone,US
002,Bob,Mr. Bob the builder,Bob the builder,UK
003,Tintin,Mr. Tin Tin,Tin Tin,FR
004,,,Rob the Bob,
005,],,Tom the Bob,
Why would Clover add a new column in to the CSV output, is it possible to stop it? I'm using maven 3.3, JDK 8 and Clover version 4.0.2.
I have tried looking for an answer but cannot seem to find anything similar to this issue. When I remove the failing tests Clover works fine.
I'm pretty sure it's connected to the code (or a library) you're using to create that CSV file. Clover on its own won't modify a CSV file. I suppose there's a code which access Java Object fields by reflection. Since class is instrumented by Clover, it adds some instrumentation code (like CLV_TEST_SNIFFER.
There are basically two solutions to your problem:
Modify the code which dumps classes to CSV to exclude static class members (this will effectively exclude Clover objects). Anyway, I believe it's not desired to dump static members to CSV which, as I assume, is a data projection of your Java object (static members don't belong to object but to class). Though, I don't know your full use case, so I may be simply wrong.
You can simply exclude files which cause problems (the ones which are serialised to CSV?) from Clover instrumentation, effectively you'll loose coverage data for those classes.

How to detect unused step definitions in cucumber-jvm junit project?

I'm running automation tests using cucumber-junit project and i've roughly around 200 scenario's in my project.. now the problem is, it's hard to find unused step definitions in my project as we constantly need to update features.. Is there any solution to detect step definitions that is no longer useful.. Any help much appreciated!!
Since cucumber-jvm 4.4.0 it is possible to use cucumber-jvm built in plugin - unused.
for cucumber junit runner it could look like this:
#RunWith(Cucumber.class)
#CucumberOptions(
plugin = {
"json:build/report/cucumber.json",
"unused:build/report/usage.txt"} //mind this plugin
glue = "stepdefs",
features = "features"
)
public class CucumberRunner {
}
After run unused stepdefs should be found in build/report/usage.txt
Original pull request: https://github.com/cucumber/cucumber-jvm/pull/1648
There can be a case where a single step can be a part of different scenarios and will have single method only in step definition. So, It is easy to map the feature file's step with the corresponding method while executing the feature file using 'cucumber feature' pulg-in.
However, It is literally not possible to cross validate the same from step definition file to identify the single step in number of feature files.
Perhaps, The only possible way out is to design your application in modular way:
1) with feature files and corresponding step definition files specific to a specific feature/module.
2) Keep generic methods in a generic parent step definition file.
Thus, Designing the application in a modular way can easily lead you to identify the unused methods that can be removed from the step definitions.
IntelliJ's cucumber plugin can search for usages of a step definition. It will not give you all unused ones in one go, but at least you can check individual usages one by one. The plugin is also available in the Community Edition of IDEA.

Categories

Resources