I am using junit 4.8 and intellij 8 and i would like to only run tests inside the IDE which are named something like *UnitTest.java.
How can this be achieved?
Found a solution with cpsuite. http://www.johanneslink.net/projects/cpsuite.jsp
Pitty it's not in the maven repo.
import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
#RunWith(ClasspathSuite.class)
#ClasspathSuite.ClassnameFilters(".*UnitTest")
public class UnitTestSuite {
}
Related
I'm upgrading a cucumber project to cucumber 6. But after the upgrade intellij doesn't recognize my steps anymore. When I run via my pom there is no issue. But if you try to go to the step definition from the feature file intellij says that there is no stepdefintion
My runner is like this
package be.nbb.hive.cucumber;
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
plugin = {"pretty"},
features = "src/test/resources/features",
glue = {"be.nbb.hive.cucumber.Steps"}
)
public class CucumberTestSuite {}
And my steps are in the package
package be.nbb.hive.cucumber.Steps;
Is this the issue or is it something else that blocks the recognision?
I had similar issue. Installing cucumber for java and gherkin IntelliJ plugins from marketplace resolved it for me
I have a peculiar problem with IntelliJ
The project libraries are showing as resolved meaning any import from the library works fine. For example, import javax.servlet.http.HttpServletRequest;
But for the java sources within the module - it fails to import them. Even a simple interface with one method , For example - public interface X { void go()} and a class implementing public Y implements X - fails to import X.
I have also an ant build which i run inside docker which compiles the project fine !
The older import of the same project works fine and I am unable to find the difference between the two.
The ant build runs fine!!. It does not compile any file , I put a next line and save the File - still it will not resolve it !!
Community Edition 2019.3
I'm trying to develop an intellij plugin written in kotlin - I'm struggling to find any examples of unit tests for the plugin that are written in kotlin, or even java ones with test data that are written using gradle rather than the older dev SDK. Is anyone able to point to a demo application with unit tests? (For inspections, ideally)
Some theory:
Testing in Gradle
Add test classes to a Gradle project
Testing Gradle plugins
Running JUnit5 tests with Gradle
Unit testing in Kotlin and kotlin.test library
Using Gradle with Kotlin
Code samples:
Article on running Kotlin Unit tests with Gradle
A tutorial on building apps with Spring Boot and Kotlin with a section on testing with Junit5
Custom Gradle plugin example
Hope this helps.
These come out of the box now if you use the template: https://github.com/JetBrains/intellij-platform-plugin-template
Here's one of the tests in Kotlin:
package org.jetbrains.plugins.template
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.psi.xml.XmlFile
import com.intellij.testFramework.TestDataPath
import com.intellij.testFramework.fixtures.BasePlatformTestCase
import com.intellij.util.PsiErrorElementUtil
class MyPluginTest : BasePlatformTestCase() {
fun testXMLFile() {
val psiFile = myFixture.configureByText(XmlFileType.INSTANCE, "<foo>bar</foo>")
val xmlFile = assertInstanceOf(psiFile, XmlFile::class.java)
assertFalse(PsiErrorElementUtil.hasErrors(project, xmlFile.virtualFile))
assertNotNull(xmlFile.rootTag)
xmlFile.rootTag?.let {
assertEquals("foo", it.name)
assertEquals("bar", it.value.text)
}
}
}
The plugin documentation also provides more relevant info for testing: https://plugins.jetbrains.com/docs/intellij/writing-tests.html
Also, here are some unit tests written in Java for the JUnit IntelliJ plugin https://github.com/JetBrains/intellij-community/blob/master/plugins/junit/test/com/intellij/execution/junit/JUnitDetectionTest.java
How to run the JUnit test suite containing a set of test cases(groovy based) from the command line. Following is the test suite class generated by eclipse.
package com.example.testclasses;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
#RunWith(Suite.class)
#SuiteClasses({ abc.class, xyz.class })
public class AllTests {
}
The above test suite works when I run the above test suite(AllTests)as JUnit from eclipse, however, I want to run the test suite(AllTests) from the command line. How do I do this?
Info: I am using Geb(Groovy) based testing where all the test cases(example: abc, def) are groovy based(having .groovy extension).
If you wish to run your tests from the command line I would suggest using a build system. My personal choice would be to use Gradle but you could probably also get away with using Maven.
The benefit of using a build system, apart from being able to run the tests from the command line, is that it will help you manage your dependencies and it will be easier to build the project for others working on the same codebase - they won't have to manually setup all the dependencies and their versions in the IDE.
Try this:
java -cp /path/to/groovy/embeddable/groovy-all-1.8.1.jar groovy.lang.GroovyShell AllTests.groovy
where 1.8.1 should be replaced with your version of groovy-all-*.jar
I recorded a test case using Selenium IDE 1.10.0. I exported the case as Java/TestNG/Remote Control.
My Eclipse version is 4.2.0 and I installed TestNG plug-in version 6.8
I am wondering how can I create a project within the eclipse to run this exported test case?
Please give me some instructions or share with me some online tutorial / documentations. Thanks!
Below is the java code generated by the Eclipse:
package com.example.tests;
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;
public class SearchDonor extends SeleneseTestNgHelper {
#Test public void testSearchDonor() throws Exception {
// set overall speed of the test case
selenium.setSpeed("4000");
selenium.open("/?html=openid");
selenium.click("css=input[type=\"submit\"]");
selenium.waitForPageToLoad("30000");
Thread.sleep(4000);
selenium.click("id=cmp_admin");
selenium.waitForPageToLoad("30000");
selenium.click("id=quicksearch_anchor");
selenium.click("css=img[alt=\"Member\"]");
selenium.waitForPageToLoad("30000");
selenium.type("id=search_name", "suzy");
selenium.click("css=input[type=\"image\"]");
selenium.click("link=Balagia, Suzy");
selenium.waitForPageToLoad("30000");
}
}
After some trial and errors. I managed to execute the exported code in Eclipse as TestNG Test. Here are the steps I took to make it compile.
1.created a Java Project within the Eclipse
2.add a class to the Java Project
2a. I copied and pasted the code into the newly created the class
3.Right click on the project>build path>configure build path
3a. on the Java Build Path window select libraries>Add External JARS, then adding all the JAR files from Selenium Java Driver folder (e.g. folder name in this case is libs), plus selenium-java-2.31.0.jar and selenium-java-2.31-src.jar
4.click the Run icon next the debug icon on the top menu bar, Run AS TestNG Test
My code is compiling, but I got some exception errors. I am getting stared on a TestNG test case!