I am trying to call my simulation model from another java program. I followed the official instructions to have the codes like below:
package test;
public class UserMain {
public UserMain(){};
public void start(){
String[] args = new String[]{"D:\\user\\model\\Repast_java\\IntraCity_Simulator\\IntraCity_Simulator.rs"};
// repast.simphony.runtime.RepastMain.main(args);
}
public static void main(String[] args) {
UserMain um = new UserMain();
um.start();
}
}
It didn't work. I think it's due to the wrong classpath. How to configure it correctly?
Note that you need to have repast.simphony.runtime/bin and the jars in repast.simphony.runtime/lib on your classpath since the runtime needs these to start.
This is more of a Java or Eclipse question about how to use Java's class path. But briefly, if you are running from the command line, you can use the -cp argument to specify the classpath. A quick google should provide the details. In Eclipse, the classpath is specified in dependencies tab in the Run Configuration (Run -> Run Configurations) for your application.
Related
My unit test in optaplanner-rewrite has this code using OpenRewrite bom 1.11.0:
#Override
public void defaults(RecipeSpec spec) {
spec.recipe(new AsConstraintBuilder())
.parser(JavaParser.fromJavaVersion()
.classpath("optaplanner-core"));
}
and it runs fine in Maven.
But when I run the unit test in my IDE (IntelliJ), I get this error:
java.lang.IllegalArgumentException: Unable to find runtime dependencies beginning with: 'optaplanner-core'
at org.openrewrite.java.JavaParser.dependenciesFromClasspath(JavaParser.java:97)
at org.openrewrite.java.JavaParser$Builder.classpath(JavaParser.java:250)
This is because my IDE window has a multiproject open, that includes both optaplanner-core and optaplanner-rewrite. There is no optaplanner-core.jar in the classpath of my test run, only optaplanner-core/target/classes.
How do I run my unit test in IntelliJ?
This is not a proper solution, but as a workaround you should be able to load the entire classpath like this:
#Override
public void defaults(RecipeSpec spec) {
List<Path> classpath = new ClassGraph().getClasspathURIs().stream().map(Paths::get).toList();
spec.recipe(new AsConstraintBuilder())
.parser(JavaParser.fromJavaVersion()
.classpath(classpath));
}
I would like to set the WebDrivers path in build.gradle rather than setting the absolute path of the driver. This would help me from not checking-in the .exe into the repo.
I am setting the driver as
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); in code.
Instead of the specifying the "/path/to/chromedriver" in code, I would like it to be picked/set by gradle whenever the test runs.
Tried below in build.gradle
test {systemProperty "webdriver.chrome.driver",
classpath.find {
it.name.contains("selenium-chrome-driver")
}
println "Getting system properties"
println System.getProperty("webdriver.chrome.driver")
}
But each I run the test, I get null
Thanks in advance.
You could also use WebDriverManager( https://github.com/bonigarcia/webdrivermanager ) to manage your drivers.
https://github.com/bonigarcia/webdrivermanager#basic-usage shows the simple way to add via gradle
dependencies {
testImplementation("io.github.bonigarcia:webdrivermanager:4.3.1")
}
and code usage:
#BeforeClass
public static void setupClass() {
WebDriverManager.chromedriver().setup();
}
#Before
public void setupTest() {
driver = new ChromeDriver();
}
i am trying to set up testing platform for our new project.
We want to use Spock 2 with JUnit 5.
And now i want to use #ExtendWith annotation in Spock based test.
Here is an example:
#SpringBootTest(classes = ExtensionTest.class)
#ExtendWith(ClassExtension.class)
class ExtensionTest extends Specification {
void "test"() {
when:
true
then:
noExceptionThrown()
}
}
Given Extension (ClassExtension) is implementing interfaces: BeforeAllCallback and AfterAllCallback.
class ClassExtension implements BeforeAllCallback, AfterAllCallback {
#Override
void beforeAll(ExtensionContext extensionContext) throws Exception {
...
}
#Override
void afterAll(ExtensionContext extensionContext) throws Exception {
...
}
}
Unfortunately it doesn't work. Extension is not being run.
What am I doing wrong?
Spock 2.x does not use the Jupiter Engine but implements its own SpockEngine and its own SpockExecutionContext based on the Jupiter API. Obviously it does not support Jupiter extensions, probably because Spock has its own extension mechanisms for annotation-driven and global extensions.
Bottom line: I recommend to port your JUnit Jupiter extension to a Spock extension. There you also have better means to hook into the Spock lifecycle.
The thread is old, but in case anyone would be searching for the similar problem, there is a way now to use Junit 5 extensions with Spock 2: spock-junit5.
I did not try it with spring boot extension, but it should work because all required jupiter extension interfaces supported by the library.
Trying to implement selenium + Cucumber + Testng instead of Junit.
My queries are
What is the alternate for #Runwith(Cucumber.class) in testng
How to run the class file which contains the path to feature file
package runner;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features="src/main/java/testCases/Cucumber/Login_Cucumber.Feature",glue="")
public class TestRunner extends AbstractTestNGCucumberTests {
}
TestNg uses #CucumberOptions tag to declare parameters
#CucumberOptions(plugin = "json:target/cucumber-report.json")
public class RunCukesTest extends AbstractTestNGCucumberTests {
}
or
#CucumberOptions(features = "src/test/resources/features/Download.feature",
glue = "uk.co.automatictester.jwebfwk.glue",
format = {"pretty"})
Check this out: https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng
Also a possible dup of :How to integrate the cucumber in testNG?
Install TestNG Eclipse Plugin. Afterwards you should be able to run TestNG Test.
First of all, Cucumber have .feature files and not test files.
Answer to your first question: 1. What is the alternate for #Runwith(Cucumber.class) in testng? "You don't need #RunWith while running with TestNG"
I didn't understand your second question but you need to understand that Cucumber runs end execute the Runner class by default and you have already defined feature files in #CucumberOptions section.
To make it more clear you can easily implement and Run Cucumber project using TestNG. The whole game is in your pom.xml file and Runner class.
Following detail also explains that you can run each scenario in cucumber as a test using TestNG.
How? It's explained below:
First of all, update your Cucumber Maven dependencies from info.cukes to io.cucumber dependencies
Following Java code in Cucumber Runner Class worked perfectly for me to run each scenario as TestNG test in feature files:
#CucumberOptions(features = "src/test/resources", plugin = "json:target/cucumber-report-feature-composite.json")
public class TestRunner {
private TestNGCucumberRunner testNGCucumberRunner;
#BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
#Test(groups = "cucumber scenarios", description = "Runs Cucumber
Scenarios", dataProvider = "scenarios")
public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper
cucumberFeature) throws Throwable{
testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
}
#DataProvider
public Object[][] scenarios() {
return testNGCucumberRunner.provideScenarios();
}
#AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
testNGCucumberRunner.finish();
}
}
Run with mvn clean test command and see the magic :)
I would be happy to see your problem resolved. Please let me know if this issue is still not resolved.
Reference: https://github.com/cucumber/cucumber-jvm/blob/master/testng/README.md
I followed this approach: https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features="src/test/resources/features",glue="stepDefinitions",tags="#Test01",plugin= {"pretty", "html:target/cucumber-reports" },monochrome=true)
public class RunnerTest extends AbstractTestNGCucumberTests{
}
It will work for sure.
This perfectly worked for me
package com.shyom.cucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
#CucumberOptions(
plugin = "json:target/cucumber-report.json",
features = "/shyom/src/test/java/feature",
glue="stepDefinations"
)
public class TestRunner extends AbstractTestNGCucumberTests{
}
I want to know if you guys know how to make BDD tests with Robotium.
As I research Robotium works with a different Virtual Machine (Dalvik) so I cannot run as Junit Test (Only with Android Junit Test). So I found a possible solution to run Robotium with Junit with RoboRemote https://github.com/groupon/robo-remote. But when i tried to integrate with cucumber the tests became unstable.
So you guys know some way to make BDD tests using Robotium?
I have successfully integrated Robotium using Cucumber-JVM for Android.
For information about the now official cucumber-android module for Cucumber-JVM and the installation, have a look here. You can also find API-documentation and examples about Cucumber-JVM here: http://cukes.info/platforms.html.
In your test-module for your app, simply add the Robotium Solo jar-file as a dependency (Scope: Compile).
One of my test-classes looks like this:
public class CucumberSteps extends ActivityInstrumentationTestCase2<YourActivity> {
private Solo solo;
public CucumberSteps() {
super(YourActivity.class);
}
#Override
protected void setUp() throws Exception {
super.setUp();
}
#Before
public void before() {
solo = new Solo(getInstrumentation(), getActivity());
}
#After
public void after() throws Throwable {
//clean up
solo.finalize();
}
#Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
#Given("^step_given_description$")
public void step_given_description() throws Throwable {
final View testView = solo.getView(R.id.testView);
solo.waitForView(testView);
solo.clickOnView(testView);
// and so on
}
}
I hope this is enough information for anyone to get started. When this question was asked, cucumber-android didn't exist yet. Keep in mind though, GUI tests are very often somewhat unstable! I managed to get a stable set of tests locally, but e.g. in Jenkins, usually some tests fail for unknown reasons.
I know it's a very old questions but the documentation on this subject is very limited so I'll post another piece of information.
This article helped me a lot: http://www.opencredo.com/2014/01/28/cucumber-android-vs-cucumber-appium/
And I used the documentation here as well (I know it's deprecated but the main project has no docs about android at all): https://github.com/mfellner/cucumber-android.
I got it to work with IntelliJ 13 Community Edition and Maven using bits from Android
Bootstrap - http://www.androidbootstrap.com/ (Mostly the Maven integration test project configuration)
Hope it helps.
I got working robotium with cucumber-jvm and androidstudio using this runner:
import android.os.Bundle;
import cucumber.api.CucumberOptions; import
cucumber.api.android.CucumberInstrumentation;
#CucumberOptions(features = {"features"}, tags = {"#smoke",
"~#pending", "~#manual", "~#reboot"})
public class Instrumentation extends CucumberInstrumentation {
private final CucumberInstrumentation instrumentationCore = new CucumberInstrumentation();
#Override
public void onCreate(final Bundle bundle) {
super.onCreate(bundle);
instrumentationCore.onCreate(bundle);
start();
}
#Override
public void onStart() {
waitForIdleSync();
instrumentationCore.start();
}
}