I have a database that stores my test results. I'm interested in writing a plugin for intellij13 that will let me rerun the test failures from the database using the JUnit run configuration. I can't find any documentation on this.
I'd like to see an example for some method like:
public void runTest(String testClass, String testName) {...}
I looked into IntelliJ 13.x and I was able to create JUnit runtime configuration. You need to do the following.
In your META-INF/plugin.xml add dependency on JUnit plugin, otherwise necessary JUnit plugin classes will not be available in your plugin class loader.
<depends optional="false">JUnit</depends>
Here's the sample code to create JUnit runtime configuration. Although it works, it is just a stub, you will have to populate all attributes.
import com.intellij.execution.RunManager;
import com.intellij.execution.impl.RunManagerImpl;
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
import com.intellij.execution.junit.JUnitConfigurationType;
import com.intellij.openapi.project.Project;
...
RunManagerImpl runManager = (RunManagerImpl) RunManager.getInstance(project);
JUnitConfigurationType type = JUnitConfigurationType.getInstance();
RunnerAndConfigurationSettingsImpl runnerAndConfigurationSettings = (RunnerAndConfigurationSettingsImpl)runManager.createRunConfiguration("junit test run", type.getConfigurationFactories()[0]);
runManager.addConfiguration(runnerAndConfigurationSettings, false);
And here we go, JUnit run configuration.
Related
Me and my team just moved from JUnit4 to JUnit5 and we faced with parallelism issues. With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore. I set up (at least I think so) junit platform engine for the project (https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine#configuration-options), but when I try to run tests via comand line (using Gradle task), I receive following error:
UnknownClass.Cucumber > UnknownClass.initializationError FAILED
org.junit.platform.commons.JUnitException at EngineExecutionOrchestrator.java:114
Caused by: org.junit.platform.commons.JUnitException at HierarchicalTestEngine.java:57
Caused by: org.junit.platform.commons.JUnitException at DefaultParallelExecutionConfigurationStrategy.java:41
Unfortunately, didn't find something in the internet, maybe someone can help with it?
What we use:
Spring boot 2.7.3
Gradle 7.5.1
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
Tasks in build.gradle that I have now:
useJUnitPlatform()
systemProperty("cucumber.junit-platform.naming-strategy", "long")
systemProperty("cucumber.execution.parallel.enabled", true)
systemProperty("cucumber.execution.parallel.config.strategy", "fixed")
systemProperty("cucumber.plugin", "html:reports/html")
systemProperty("cucumber.plugin", "pretty")
systemProperty("cucumber.plugin", "junit:reports/junit")
doLast {
javaexec {
mainClass.set("io.cucumber.core.cli.Main")
classpath = cucumberRuntime + sourceSets.test.get().output + sourceSets.main.get().output
}
}
}
tasks {
val consoleLauncherTest by registering(JavaExec::class) {
dependsOn(testClasses)
val reportsDir = file("$buildDir/test-results")
outputs.dir(reportsDir)
classpath = sourceSets["test"].runtimeClasspath
mainClass.set("org.junit.platform.console.ConsoleLauncher")
args("--scan-classpath")
args("--include-engine", "cucumber")
args("--reports-dir", reportsDir)
}
test {
dependsOn(consoleLauncherTest)
exclude("**/*")
}
}
Configuration class:
#CucumberContextConfiguration
#Suite
#IncludeEngines("cucumber")
#SelectClasspathResource("com/example")
#ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.example")
#SpringBootTest
#ContextConfiguration(classes = [IntegrationContext::class], loader = SpringBootContextLoader::class)
class Application() {}
Your question is pretty much impossible to answer because you didn't go through the process of making a minimal reproducer. For your next question please read the "Help others reproduce the problem" section in How do I ask a good question?.
With 4th version we used -Dcucumber.options="--threads 5" to run in tests several threads, but after deprecation and removing of cucumber options it's obviously doesn't work anymore.
Project typically include a CHANGELOG and release notes documenting all relevant changes.
What we use:
Spring boot 2.7.3
Cucumber java, junit, spring, junit-platform-engine 5.7.0
junit-platform-suite-api 1.3.2
These dependencies don't converge and aren't quite correct. You'll want to use Cucumber's and JUnit's Bill of Materials to avoid having to specify the version for every module.
If you're using Spring Boot in the recommended way you may also be able to omit the junit-bom altogether.
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation(platform("io.cucumber:cucumber-bom:7.9.0"))
testImplementation("io.cucumber:cucumber-java")
testImplementation("io.cucumber:cucumber-junit-platform-engine")
testImplementation("org.junit.platform:junit-platform-suite")
testImplementation("org.junit.jupiter:junit-jupiter")
}
Tasks in build.gradle that I have now:
So in this build file it appears that you are trying to run Cucumber in 3 different ways. Through the JUnit Platform, through Cucumbers CLI and through the JUnit 5 ConsoleLauncher.
I don't know which solution you are trying use but suppose that you want to use the JUnit Platform, then you look at cucumber-java-skeleton for a working example.
Then afterwards you should clean up your build file. :D
I have a problem using Junit tests with Java and Eclipse. All of my tests run just fine when I invoke them standalone. By this I mean that HDLmTreeTest, HDLmTreeTest1, and HDLmTreeTest2 all run fine when I run them by themselves. However, I have a Java source module with all of the test files in it. See below.
package com.headlamp;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.runner.RunWith;
#RunWith(JUnitPlatform.class)
#SelectClasses({HDLmConfigTest.class, HDLmDefinesTest.class,
HDLmErrorTest.class, HDLmStringTest.class, HDLmTreeTest.class,
HDLmTreeTest1.class, HDLmTreeTest2.class,
HDLmModTest.class, HDLmBuildJSTest.class, HDLmFindTest.class,
HDLmAssertTest.class, HDLmBuildLinesTest.class, HDLmUtilityTest.class,
HDLmSavedChangeTest.class, HDLmCurlApacheTest.class, HDLmMainTest.class,
HDLmJettyTest.class, HDLmCurlJettyTest.class, HDLmEditorServletTest.class,
HDLmApacheTest.class, HDLmProxyTest.class, HDLmSessionTest.class,
HDLmLogMsgTest.class, HDLmMatchTest.class, HDLmImageInformationTest.class,
HDLmClusteringTest.class, HDLmJsonTest.class})
class HDLmAllTests { }
When I run this file, all of my tests get invoked except for HDLmTreeTest1.class and HDLmTreeTest2.class. I should say that HDLmTreeTest1.class and HDLmTreeTest2.class were just recently created and added to the SelectClasses list. For some reason, they are not invoked, but all of the other classes are invoked. What am I doing wrong?
I figured this out (with lots of online help). The problem was the name(s) of my test classes. Test classes (the names of test classes) must end with 'Test' or 'Tests'. They can not end with 'Test1' or 'Test2'. That was my error. I changed the class names and the problem went away. See https://howtodoinjava.com/junit5/junit5-test-suites-examples/ for some details.
Environment Details
Mac OS X 10.9
Oracle JDK 1.7.0_55 64-bit
jython-standalone-2.5.3.jar
junit-4.11
What I have done so far
I have added the junit jar to /Library/Java/Extensions.
I invoked Jython as follows java -jar jython-standalone-2.5.3.jar
In the Jython interpreter, I imported the following import org.junit.Assert, and this import was successful.
Problem
When I tried to use assertTrue, I got a NameError in the interpreter. Why is this so?
I understand that assertTrue is a static method. Not sure what implication this has when I try to use it in Jython.
Additional Context
I am using XMLUnit in Jython. Was able to successfully import the Diff class from org.custommonkey.xmlunit in Jython. Also able to use the methods in this class, and call them on a Diff object. The result of this method call is what I am trying to pass to assertTrue, when it throws the error.
from org.custommonkey.xmlunit import Diff
import org.junit.Assert
xml1 = ...some XML string...
xml2 = ...some XML string...
myDiff = Diff(xml1, xml2)
assertTrue(myDiff.similar())
Hope this additional information is useful in identifying a solution to this problem.
Latest Status
I narrowed it down to setting this property python.security.respectJavaAccessibility = false, since the Assert() constructor is protected.
Still trying to get it to work. Any help is greatly appreciated.
Figured it out.
In addition to junit.jar file, the hamcrest-core.jar file also needed to be copied to /Library/Java/Extensions.
Then I got rid of the jython.jar file, and instead installed it using the jython installer.
After the installation was completed, I updated the registry file in the installation folder, specifically setting this property python.security.respectJavaAccessibility = false.
Now I am able to see the assertTrue method, and no longer getting a NameError.
I do the following:
From the Package Explorer I select "New, Other, JUnit Test Case"
I write this code:
package dk.sample;
import org.junit.*;
import static org.junit.Assert.*;
public class TestCase {
#Test
public void alwaysTrue(){
assertTrue( true );
}
}
I then select "Run As, JUnit test"
Get this error: "Class not found dk.sample.TestCase
java.lang.ClassNotFoundException: ...."
What do I miss? Have tried with different Run Configurations - but it seems like I miss a classpath somewhere? But to what and where?
To make JUnit work within Domino Designer you need to perform few additional steps:
set up source control for your application
adjust the on-disk project to be recognized as Java application
run JUnit tests within your on-disk project
Please note that java agents have to be tested in a different way..
You can find more detailed explanation about enabling JUnit for both XPages and Agents in the following blog post: Unit Tests for Lotus Domino Applications
Here's also a great how-to on this topic.
Coundn't get JUnit to work inside the Domino Designer. Instead of running the tests from DDE, I now run the tests from a XPages. This works like a dream. Made my own 'JUnit runner' class - that is, I just call the JUnit runners but handles the result my self in order to display it as html on the XPage.
Code can be found here: http://xpages.dk/wp-content/uploads/2013/10/junitrunner.txt
Danish blog post here: http://xpages.dk/?p=1162
I have implemented a very high number of test cases and I would like to avoid running them all at once.
I created my own TestSuite in order to select only a bunch of them:
package com.mytests;
import junit.framework.Test;
import junit.framework.TestSuite;
import com.mytests.MyTestClass1;
import com.mytests.MyTestClass2;
import com.mytests.MyTestClass3;
public class CustomSuite extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(createTest(MyTestClass1.class, "test3"));
suite.addTest(createTest(MyTestClass2.class, "test2"));
suite.addTestSuite(MyTestClass3.class);
return suite;
I am able to launch it through Eclipse (Run As >> Android JUnit Test) without any problem. But my goal is to be able to run it through the startcts script.
cts_host > start --plan MyPlan -p com.mytests.CustomSuite
The specific test package does not exist: com.mytests.CustomSuite
cts_host > start --plan MyPlan -t com.mytests.CustomSuite#Test
The specific test does not exist: com.mytests.CustomSuite#Test
I am running out of ideas. Does anyone know how to do that?
Thanks,
Vincent
I'm not expert in this area, but I have one thing to advice.
In CTS, there is plans directory which contains xml files. They contains list of CTS test which is used startcts. Is your test in any of them?