I am trying to run TestSuite using Junit 5. Individual file run fine. But TestSuite is not running when executed from command line. I am using junit-platform-console-standalone-1.6.0.jar to run tests.
My Test classes are:
package demo;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
public class TestDemoClass1 {
#Test
public void test1() throws Exception {
System.out.println("Test 1 from DemoClass 1");
}
#Test
public void test2() throws Exception {
System.out.println("Test2 from DemoClass 1");
}
}
My Suite calss is:
package demo;
import org.junit.platform.suite.api.SelectClasses;
import org.junit.platform.suite.api.Suite;
#Suite
#SelectClasses({ TestDemoClass1.class })
public class TestSuite {
}
The command I am usign to run from command lines:
java -jar target/junit-platform-console-standalone-1.6.0.jar -cp .;target/test-classes/ -c demo.TestSuite
This is resolved ":https://github.com/junit-team/junit5/issues/2813.
The issue was not adding set of jars while runnign command needed for console launcher.
Additional info in above GitHub issue link but in summary you need to add following jars to classpath:
junit-platform-console-standalone-1.8.2.jar;
junit-platform-suite-api-1.8.2.jar;
junit-platform-suite-commons-1.8.2.jar;
junit-platform-suite-engine-1.8.2.jar; \
Related
I'm trying to set up Kotlin for VS Code following the instructions in this article, which basically says to install the Kotlin and Code Runner extensions.
So far, so good, I am able to run the following code:
App.kt:
fun main() {
MyApp().printTest()
}
class MyApp {
fun printTest() {
println("Hello test")
}
}
However, when I try to extract the MyApp class to another file in the same folder, I can't import it:
App.kt:
import MyApp.MyApp // import MyApp doesn't work also
fun main() {
MyApp().printTest()
}
MyApp.kt:
class MyApp {
fun printTest() {
println("Hello test")
}
}
I've tried to import the Java Import Snippets extension, but it doesn't work, showing a unresolved reference for MyApp.
Am I missing some extension or VS Code configuration?
That's the command VS Code is running:
cd ".../testapp/src/" && kotlinc App.kt -include-runtime -d App.jar && java -jar App.jar
Should it reference MyApp.kt somehow?
Note: I'm on Debian.
You have no project's package name defined.
Put the files App.kt and MyApp.kt in the same folder level.
In App.kt, only use
import MyApp // or no import at all,
fun main() {
MyApp().printTest()
}
Read more about Java/Kotlin package
I'm having a karate test project where my folder structure would be like below, I have organized the folder (hunting-skills) based on the type. I have configured cucumber reporting and parallel execution with 1 thread, below is the code for parallel execution and cucumber reporting
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import static org.junit.jupiter.api.Assertions.*;
public class FeatureTests {
#Test
public void testAll() {
Results results = Runner.path("classpath:hunting-skills").tags("~#ignore").parallel(1);
generateReport(results.getReportDir());
assertEquals(0, results.getFailCount(), results.getErrorMessages());
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
ArrayList<String> jsonPaths = new ArrayList<>(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "someTests");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
src/test/java
|
+--karate-config.js
+--FeatureTests.java
|
\-- hunting-skills
\-- animals
|
+-- lionTest.feature
+-- tigerTest.feature
|
\-- birds
|
+-- valtureTest.feature
+-- eagleTest.feature
|
The complete suite ran when the following command ./gradlew test -Dkarate.options="--tags ~#ignore" -Dtest=FeatureTests is run in terminal (say git bash or Linux terminal) which is expected.
But at times I want to run a specific folder or *.feature file. I have got commands from the karate GitHub page https://github.com/intuit/karate
(to run specific folder) ./gradlew test "-Dkarate.options=--tags ~#ignore classpath:hunting-skills/animals Dtest=FeatureTests
(to run specific file) ./gradlew test "-Dkarate.options=--tags ~#ignore classpath:hunting-skills/animals/lionTest.feature Dtest=FeatureTests
When I run the command for a specific file, the complete suite ran. Please help
Write another test entry point that does not set the path() or read system properties manually and use Java code and if-then conditions. Don't waste your time trying to "re use".
I am new to Selenium grid. My hub and the node is running. I tried a test to automate in the node. But I am getting the error "Could not initialize class org.openqa.selenium.os.Kernel32". I could not find the solution anywhere. Please help
My code is :
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.net.URL;
import java.net.MalformedURLException;
public class TestGrid {
WebDriver driver;
String baseURL, nodeURL;
#BeforeTest
public void setup() throws MalformedURLException{
baseURL = "http://newtours.demoaut.com/";
nodeURL = "http://192.168.0.6:5566/wd/hub";
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(Platform.WIN8);
driver = new RemoteWebDriver(new URL(nodeURL), capability);
}
#Test
public void verifyTitle() {
String actualTitle = driver.getTitle();
String expectedTitle = "Welcome: Mercury Tours";
Assert.assertEquals(actualTitle, expectedTitle);
}
#AfterTest
public void closeSetup(){
driver.quit();
}
}
I had the same problem. And there was another error message appearing frequently.
org.openqa.selenium.WebDriverException: Native library (com/sun/jna/windows-x86-64/jnidispatch.dll) not found in resource path ([file:/C:/Users/admin/work/Selenium-batch-files/Windows/selenium-server-standalone-2.47.1.jar])
To solve the problem, I manually create selenium standalone jar file with jnidispatch.dll in correct path.
The steps below.
1) unzip selenium-server-standalone-2.47.1.jar using 7-zip. Then find out the "jnidispatch.dll" does exist, but no /com/sun/jna/windows-x86-64/ directory.
2) Create a directory .../com/sun/jna/windows-x86-64/ and copy "jnidispatch.dll" in.
3) create jar file.
"C:\Program Files\Java\jdk1.8.0_45\bin\jar.exe" cf yournewselenium.jar *
Note: you need to be in unzipped folder.
4) To run runSeleniumHub.bat and runSeleniumNode.bat, still complain "no menifest attribute". To fix this, change file
From:
call java -jar selenium-server-standalone-2.47.1.jar -role hub
To:
call java -cp yournewselenium.jar org.openqa.grid.selenium.GridLauncher -role hub
And on runSeleniumNode.batch
From:
call java -Dos.name=windows -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe -jar selenium-server-standalone-2.47.1.jar -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS"
To:
call java -Dos.name=windows -Dwebdriver.chrome.driver=chromedriver.exe -Dwebdriver.ie.driver=IEDriverServer.exe -cp yournewselenium.jar org.openqa.grid.selenium.GridLauncher -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS" -browser "browserName=chrome,platform=WINDOWS" -browser "browserName=firefox,platform=WINDOWS"
After the above changes, the problem is fixed. The error message not appear any more.
just dont use parameters
os.name, os.arch, os.version
when you run command
java -jar selenium-server-standalone-xxx.jar
(solution was tested on windows 10)
I was facing the same problem. After using proper URL, my problem has gone.
You should try with: http://www.yoursite.com
Also have a look here: https://stackoverflow.com/a/22149459/4921776
I try to run "gradle test", and get error
My test is
class HelperTest extends ro.gd.Test {
Plugin o;
void setUp() {
o = new Plugin();
}
void testGetIdeaDeps() {
def r = o.ideaDeps
asrHaveVal r
}
}
when i run gradle test, it raise:
junit.framework.AssertionFailedError: Exception in constructor: testGetIdeaDeps (java.lang.NoClassDefFoundError: Could not initialize class groovy.lang.GroovySystem
at org.codehaus.groovy.reflection.ClassInfo.isValidWeakMetaClass(ClassInfo.java:221)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassForClass(ClassInfo.java:191)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:236)
at ro.gd.idea.HelperTest.$getStaticMetaClass(HelperTest.groovy)
at ro.Test.<init>(Test.groovy)
at ro.gd.Test.<init>(Test.groovy)
at ro.gd.idea.HelperTest.<init>(HelperTest.groovy)
...
Here is my full code
I fix this question. the reason is "groovy.lang.GroovyRuntimeException: Conflicting module versions", for detail, following is my build.gradle
compile 'org.codehaus.groovy:groovy-all:+'
compile gradleApi()
I guess gradleApi() will auto "compile localGroovy()", and this groovy version is 2.3.6, but latest version is 2.4.3
I find this error message in one test report
the solution is to specify groovy version like following
compile 'org.codehaus.groovy:groovy-all:2.3.6'
and you check your groovy version with 'gradle dependencies|grep groovy'
Do JUnit test suites work in Grails?
I am writing a Groovy/Grails(2.1.2) project using IntelliJ.
Is it possible to run Spock tests as a JUnit test suite? I have tried:
package com.foo
import com.foo.functional.SampleFunctionalSpec
import org.junit.experimental.categories.Categories
import org.junit.runner.RunWith
import org.junit.runners.Suite
#RunWith(Categories.class)
#Categories.IncludeCategory(Category1.class)
#Suite.SuiteClasses( {SampleFunctionalSpec.class} )
class SampleTestSuite {
}
and
package com.foo.functional
import com.foo.*
import org.junit.experimental.categories.Category;
#Category(Category1.class)
class SampleFunctionalSpec extends BloomGebSpecCase {
def "Sample test 1 with Category1"() {
given:
when:
println "when"
then:
println "Sample test 1 with Category1"
}
}
and
package com.foo
interface Category1 { }
and I get "Unable to attach test reporter to test framework..." when I run grails test-app functional SampleTestSuite from within IntelliJ.
EDIT: Also, just running a test suite with no categories gives same "Unattached" problem:
#RunWith(Suite.class)
#Suite.SuiteClasses( SampleFunctionalSpec.class )
class SampleTestSuite { }