When I run to run this test with a feature it complains it cannot find the steps. I have tried defining them in Java 8 style, and Java 7 style and using IntelliJ to generate the steps into a MyStepdefs class but it cannot find them.
I am using version 1.2.4 of cucumber-java8 and cucumber-junit.
import cucumber.api.CucumberOptions;
import cucumber.api.DataTable;
import cucumber.api.PendingException;
import cucumber.api.java8.En;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
#RunWith(Cucumber.class)
#CucumberOptions(
monochrome = true,
glue = {"com.mycom.core.agg.RunCukesTest"})
public class RunCukesTest implements En {
public RunCukesTest() {
Given("^I have PriceLevels$", (DataTable arg1) -> {
});
And("^I have a TradeRequest$", (DataTable arg1) -> {
});
Then("^I should get these LegRequests$", (DataTable arg1) -> {
});
}
}
running the test prints
Running com.mycom.core.agg.RunCukesTest
1 Scenarios (1 undefined)
3 Steps (3 undefined)
0m0.000s
You can implement missing steps with the snippets below:
Given("^I have PriceLevels$", (DataTable arg1) -> {
.. rest deleted ...
Running the feature file from IntelliJ give much the same error.
While we couldn't figure out what the cause was, create a new maven project with a minimum of dependencies "fixed" the problem. We didn't need to change the code.
Related
So I am trying to make a minecraft mod that has a randomly generated ore. I have run into a problem in this part of the code.
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.ConfiguredPlacement;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;
public class ModOreGen {
public static void generateOre() {
for (Biome biome : ForgeRegistries.BIOMES) {
if (biome == Biomes.BAMBOO_JUNGLE) {
ConfiguredPlacement<CountRangeConfig> customConfig = Placement.COUNT_RANGE
.func_227446_a_(new CountRangeConfig(9, 10, 10, 0));
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES,Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, blockinit.chocolate_ore.getDefaultState(), 10)).withPlacement(customConfig));
}
}
}
}
Where it says .withConfiguration it gives me the error:
The method withConfiguration(OreFeatureConfig) is undefined for the type Feature<OreFeatureConfig>
I have already tried updating my mappings and such, but nothing helped. This has been a problem that has really irritated me for days now. What is happening?
I just had this same problem with my code and finally fixed it. Try this out!
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.ConfiguredPlacement;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;
public class ModOreGen {
public static void generateOre() {
for (Biome biome : ForgeRegistries.BIOMES) {
if(biome == Biomes.BAMBOO_JUNGLE) {
ConfiguredPlacement<?> customConfig = Placement.COUNT_RANGE
.configure(new CountRangeConfig(9, 10, 10, 0));
biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(newOreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE,BlockInit.chocolate_ore.getDefaultState(), 10)).withPlacement(customConfig));
}
}
}
}
The obvious thing Sammerson did was to remove the strong typing for CountRangeConfig:
ConfiguredPlacement<?> , but that doesn't matter.
What you can't see is updating Forge to 1.15.2.
This is most likely your best fix. In your build.gradle, somewhere near the top (mine is line 28) you've probably already updated your mappings to:
mappings channel: 'snapshot', version: '20200409-1.15.1'
But you also want to go down and update the Forge version also (this is around line 90 for me).
dependencies {
minecraft 'net.minecraftforge:forge:1.15.2-31.1.0'
}
You need to do the same
gradlew genEclipseRuns
gradlew eclipse
just like updating the mappings.
(You can check the Forge page, there may be a newer version than 1.15.2 by the time someone else reads this. And I hope anyone using IntelliJ can figure out how to update your own mappings/forge.))
I am working on porting a JUnit4 based test framework that uses JUnitCore to launch unit tests with JUnit5 launcher, junit-vintage-engine and a LauncherDiscoveryRequest with ClassSelector.
It is working for all cases except #ParameterizedTest. Launcher is not honoring parameterized tests.
How do I get Launcher to honor JUnit4 parameterized tests?
I have tried adding testCompile("org.junit.jupiter:junit-jupiter-params:${junit_jupiter_version}")
package ...;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import ...TestCategory;
import ...TestType;
import ...DataScramblingRegexTest;
#TestType(...TestCategory.UNIT)
#RunWith(Parameterized.class)
public class RegexGenTest {
private static final int LOOKAROUND_ATTEMPTS = 100;
#Parameterized.Parameter(0)
public String regex;
#Parameterized.Parameters(name = "{index}: RegexGenTest: {0}")
public static Iterable<String[]> data() {
return DataScramblingRegexTest.data();
}
#Test
public void testTransformAndGenerate() {
//even though Data Scramble Random Text doesn't transform every regex,
//even if we do, and run it through Generex, it should still work.
final String transformedRegex = RegexGen.transform(this.regex);
String randomStr = RegexGen.generate(transformedRegex);
if (RegexGen.containsLookArounds(this.regex)) {
for (int i = 0; i < LOOKAROUND_ATTEMPTS; i++) {
randomStr = RegexGen.generate(transformedRegex);
if (randomStr.matches(this.regex)) {
return;
}
}
Assert.fail("Lookaround failed");
}
Assert.assertTrue("generated string does not match regex: " + randomStr, randomStr.matches(this.regex));
}
}
build.gradle
compile("junit:junit:${junit_version}")
testCompile("org.junit.vintage:junit-vintage-engine:${junit_jupiter_version}")
testCompile("org.junit.jupiter:junit-jupiter-api:${junit_jupiter_version}")
testCompile("org.junit.jupiter:junit-jupiter-params:${junit_jupiter_version}")
testCompile("org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}")
where
junit_version=4.12
junit_jupiter_version=5.4.2
Note the proprietary TestCategory.UNIT annotation, we use this in our test discovery code and create a Launcher and a LauncherdiscoveryRequest with ClassSelector.
I expect JUnit 4 parameters to be supported by JUnit5 launcher with junit-jupiter-vintage engine and it is not supported.
Here is my code snippet for parallel execution:
package examples;
import com.intuit.karate.KarateOptions;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
#KarateOptions(tags = {"~#ignore"})
public class ExamplesTest {
#Test
public void testParallel() {
List<String> tags = Arrays.asList("~#ignore");
List<String> features = Arrays.asList("classpath:examples/autocomment");
Results results = Runner.parallel(tags,features, 5, "target/surefire-reports");
// assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
}
Once all feature files executed using command
mvn test -DargLine="-Dkarate.env=qa",threads did not exit and hence build never gets concluded.
Could you please let me know if I am doing anything wrong here??
`
One of your tests probably has a severe error (maybe the eval of karate-config.js). Run using the JUnit runner and see the logs.
This should be fixed in this ticket, do see if you can build from source and validate: https://github.com/intuit/karate/issues/667
When I try to run my code, it only shows cucumber skeleton. I use a JUnit runner class as JUnit test suite.
Code is below for all three classes.
Feature is :
Feature: Check addition in Google calculator
In order to verify that google calculator work correctly
As a user of google
I should be able to get correct addition result
#Runme
Scenario: Addition
Given I open google
When I enter "2+2" in search textbox
Then I should get result as "4"
Selenium Class :
package cucumberTest;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumTest {
private SeleniumTest()
{
}
private static WebDriver driver = null;
public static void seleniumTest() {
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
//Put a Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//Launch the Online Store Website
driver.get("http://www.store.demoqa.com");
// Find the element that's ID attribute is 'account'(My Account)
driver.findElement(By.xpath(".//*[#id='account']/a")).click();
// Find the element that's ID attribute is 'log' (Username)
// Enter Username on the element found by above desc.
driver.findElement(By.id("log")).sendKeys("testuser_1");
// Find the element that's ID attribute is 'pwd' (Password)
// Enter Password on the element found by the above desc.
driver.findElement(By.id("pwd")).sendKeys("Test#123");
// Now submit the form. WebDriver will find the form for us from the element
driver.findElement(By.id("login")).click();
// Print a Log In message to the screen
System.out.println("Login Successfully");
// Find the element that's ID attribute is 'account_logout' (Log Out)
driver.findElement (By.xpath(".//*[#id='account_logout']/a")).click();
// Print a Log In message to the screen
System.out.println("LogOut Successfully");
// Close the driver
driver.quit();
}
}
JUnit Class:
package cucumberTest;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
//#CucumberOptions(
// features = "Feature/googleCalc.feature"
////,glue={"stepDefinition"}
// )
#CucumberOptions(
features = {"Feature/googleCalc.feature"},glue={"stepDefinition"},
plugin = {"pretty"},
tags = {"#Runme"}
)
public class TestRunner {
}
Step Definitions :
package stepDefination;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;
import cucumberTest.SeleniumTest;
public class googleCalcStepDefinition {
#Given("^I open google$")
public void i_open_google() throws Throwable {
// Write code here that turns the phrase above into concrete actions
SeleniumTest.seleniumTest();
}
#When("^I enter \"(.*?)\" in search textbox$")
public void i_enter_in_search_textbox(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
SeleniumTest.seleniumTest();
}
#Then("^I should get result as \"(.*?)\"$")
public void i_should_get_result_as(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
SeleniumTest.seleniumTest();
}
}
Output shown is :
Feature: Check addition in Google calculator
In order to verify that google calculator work correctly
As a user of google
I should be able to get correct addition result
#Runme
Scenario: Addition [90m# Feature/googleCalc.feature:7[0m
[33mGiven [0m[33mI open google[0m
[33mWhen [0m[33mI enter "2+2" in search textbox[0m
[33mThen [0m[33mI should get result as "4"[0m
1 Scenarios ([33m1 undefined[0m)
3 Steps ([33m3 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
#Given("^I open google$")
public void i_open_google() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#When("^I enter \"(.*?)\" in search textbox$")
public void i_enter_in_search_textbox(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
#Then("^I should get result as \"(.*?)\"$")
public void i_should_get_result_as(String arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
I found the reason it was not executing because i added Selenium test class and Junit runner class in Package cucumberTest; and skeleton was in package stepDefination; so what i did was i moved skeleton to pacakge cucumberTest; where junit runner and selenium classes are it resolved the issue for . Issue was occuring because when you place Junit class in package it will search for skeleton in that package but if you add JUnit runner class in source folder then it will be able to find the page under src folder
First, I am seeing a lot of questions about the use of the JavaCompilerAPI, I want to clarify that I am creating an on-line simulation builder that takes too many inputs from the user to precreate classes. That is why I am using a java compiler in order to write the classes using the user's inputs.
As for my problem, I have tested with some basic compiler programs, and am presently working of code found here: Dynamic Compiling Without Create Physical File
The compilation of the code is successful, however when I run the code,
ToolProvider.getSystemJavaCompiler();
returns null.
From other entries I understand one cause might be that the default java.home is JRE, so I added the line where I set java home to my JDK version:
System.setProperty("java.home", "C:\\Program Files (x86)\\Java\\jdk1.7.0_51;");
I have also added tools.jar to the folder with my program, and called the program specifying tools.jar in the classpath like so:
java -cp ".;tools.jar" Compiler
These approaches have not changed anything. Any ideas about what might be the problem?
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.*;
public class Compiler {
static final Logger logger = Logger.getLogger(Compiler.class.getName());
static String sourceCode = "class HelloWorld{"
+ "public static void main (String args[]){"
+ "System.out.println (\"Hello, dynamic compilation world!\");"
+ "}"
+ "}";
public void doCompilation() {
System.out.println(System.getProperty("java.home"));
System.setProperty("java.home", "C:\\Program Files (x86)\\Java\\jdk1.7.0_51;");
System.out.println(System.getProperty("java.home"));
SimpleJavaFileObject fileObject = new DynamicJavaSourceCodeObject("HelloWorld",sourceCode);
JavaFileObject javaFileObjects[] = new JavaFileObject[]{fileObject};
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
System.out.println(compiler);
StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, Locale.getDefault(), null);
...