I am performing automation setup using java, cucumber and junit. However, due to restrictions of firewall and proxy in company, not able to create maven project with archtype templates. Hence initially created java project with source folder as src/test/java, placed feature file, stepdefinition and test runner class within this source folder, however, while running test runner class, I am facing "test class not found error for selected project".
I tried all sort of solutions such as ordering JRE file to bottom, giving entire path of feature file,adding output folder in using run configuration etc however it seems not working.
Hence finally would like to know whether can we run cucumber with only java and junit in the absence of maven.
Kindly help me in resolving this issue.
Related
I need to run my Selenium scripts in Jmeter. I would like to use Junit request. To reach this I need to make a .jar file from my test file. But I dont know how.
This is my class with the test:
When I try to make a .jar using: File -> Project Structure -> Artifacts -> + -> Jar from modules with dependencies -> here I am trying to choose class:
but it is not possible because my Login class is "Unit test class".
Is it possible to make .jar file from Unit test class somehow? And will the depedendecies in my pom.xml be preserved?
I tried to make it under Main class, but there is a problem with a JUnit annotations.
I wasnt able to achieve this with these tips unfortunatelly :( https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
You don't need to choose a main class because you're not creating an executable jar, you're creating a .jar with tests
You need to tick "include tests" box
I believe it would be easier to go for Maven Jar Plugin (from your own link) in combination with Maven Assembly Plugin to add all transitive dependencies.
And the easiest would be just switching to WebDriver Sampler which can be installed using JMeter Plugins Manager and put your code there, it will be much easier to debug and amend it, moreover you won't have to take care about running it with > 1 threads
I'd like to run tests with JUnit 5 on Java 9 modular project in Eclipse, with no Maven, Gradle or all that fancy stuff. So I have src/main/java path where module-info.java and module's packages live and also src/test/java where all the test classes are. Id est business as usual, prior to the Jigsaw module system. I have Eclipse Oxygen.3a (4.7.3a) an Java 10.0.1.
I've seen some video from Eclipse showing, how to add JUnit test to modular project, but this flabbergasted me deeply: they put required keyword into module-info.java of a module, binding it to JUnit module. Is that actually even correct?
I've seen also all these --patch-module/--add-reads solutions (when we're talking about working in a console) and it seems like it's the proper way to do it, but I have no idea, how to achieve that in Eclipse without binding module under test to JUnit module. Is that even possible in Eclipse (without Maven and s.o)?
I tried to solve this problem for quite a while, too. My approach is to add a filter to the source code directory for src/main/java that filters out the module-info.java. This allows to have a different module-info.java in src/test/java. It will be this one that gets copied to the output folder. This way you can run your unit tests from within the IDE and use the other one for the final build. However, you need to keep the content of the one in src/main/java updated yourself.
Right click on the project > Properties > Java Build Path > Source
Select the src/main/java entry, click Edit > Next > Exclusion Patterns > Add
I have an automation job (Java, Selenium and Cucumber) on jenkins. I'd like to know if it's possible to store my feature files somewhere on jenkins and configure my java project to read these features there. So doing this everyone who needs to edit the feature file can simple access the jenkins file and edit then, otherwise it would be necessary access the java project, edit the feature and commit and push it to the git repository (too complicated)
Should work if you change the features option for #CucumberOptions in your cucumber runner class. Just make it point to a different folder containing the feature files.
Yes, its possible. Jenkins downloads the code from repo to a slave jenkins node on which the test is executed. The feature files should be located on this node. The build tool or the configs (Maven/etc) should include the feature file locations in the test phase or the test plugins used. The #CucumberOptions also would then specify these feature files to run for the runner.
Note that #CucumberOptions is checked into the repo so you want to make that as generic as possible and then control the feature files in the jenkins node.
I'm using eclipse for my IDE. I'm using Maven to build / release my code. Ideally I'd like to only have 1 build engine. To that end I want to make sure that I build/test the code the same way everytime.
However, the Junit View in Eclipse is nice an easy to use. I'd like to keep using it while debugging my tests.
A couple years ago I managed to do this with Intellij IDEA, so I figure something similar should be possible in Eclipse.
How can I build (and hopefully test) with Maven and then view the results of testing in Eclipse?
The maven-surefire-plugin generates reports after executing the tests, that are located by default in target/surefire-reports:
The Surefire Plugin is used during the test phase of the build lifecycle to execute the unit tests of an application. It generates reports in two different file formats:
Plain text files (*.txt)
XML files (*.xml)
By default, these files are generated at ${basedir}/target/surefire-reports.
As such, after the tests are executed, you just need to open those reports in Eclipse by double-clicking them.
If you open the XML reports, Eclipse will, by default, open the JUnit view and you will have the same presentation as you're used to when running the test directly in Eclipse.
I'm developing a project in Eclipse JDT, that has optional dependencies on OSGI - that is, it supports being used as an OSGI bundle, and if it is used as a bundle inside an OSGI environment, it will also reference some classes from OSGI.
Now I want to write JUnit test cases for both running inside OSGI and running without OSGI, included in two different test suites. The OSGI tests are run as JUnit Pulg-in Tests and the Non-OSGI tests should be run as normal JUnit Tests.
Now I have the problem, that I couldn't find any way in Eclipse to exactly specify the classpath for the JUnit Test Run Configuration and exclude the optional OSGI jars.
Is there any way to exclude jars or modify the default classpath for an Eclipse Run Configuration?
If not, does anyone have a suggestion, how one should setup JUnit tests in such a case?
The only solution I was able to find is, to create a jar file from my unit tests and run the tests without OSGI from a different project with the test jar file on the classpath. But I would prefer a more elegant solution, ideally without the necessity of a second test project.
With the help of Gimbys comment, I was able to solve the problem. Although it is not possible in Eclipse to modify the default classpath generated by JDT, it is possible to entirely remove the default classpath and then add your own classpath in the classpath tab of the Runtime Configuration.
To remove the default classpath, one has to select the root entry that is named after the currently run project, and then click on the "remove" button. After that one can add all the jar files and projects that should be loaded in the classpath. The downside of this approach is, that jar files, that are normally provided by Eclipse plugins like e.g. junit.jar, must then also be selected manually (e.g. by adding it to a library folder of the project or by selecting the external jar in the plugins directory of the Eclipse installation folder).
I would suggest that you split up your project in 4 separate projects:
Logic: This package contains all the logic, so basically what your program/plug-in does
Logic.plugin: This Project resembles a Plugin-Project (OSGI-Bundle). This project contains only configurations needed for your plugin and everything dependent on osgi. It has a dependency on your Logic Project.
Logic.plugin.test: All the test cases for your osgi bundle. It is the normal plugin approach to split up logic and test cases
Logic.cli: This project contains the command line interface (or whatever your alternate application is). This also depends on the Logic project.
If your CLI project is only very small you may merge it with the Logic project.