In keeping with the m2e bug/issue, I followed the solution mentioned #SL4j m2e fails to load in Eclipse IDE.
My Pom.xml looks like this (for my JUnit and Selenium dependencies):
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>TestJUnit</groupId>
<artifactId>TestJUnit</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.41.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.41.0</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
However when I do a mvn compile I get the following kind of error:
[ERROR] /path:/to/file/<foldername>/<JUnitClassName>.java:[9,17] package org.junit does
not exist
I am new to maven, is there something that I am doing wrong here.
In your <dependencies> list, you specified JUnit with the scope of test, which means that it is only included in the jar when you do mvn test, but not included in mvn compile. If you want JUnit to be included in your final jar, change the <scope>test</scope> to <scope>compile</scope> or you can jsut remove the tine, they both do the same.
TL;DR use mvn test to test your application; or change <scope>test</scope> to <scope>compile</scope> in the junit dependeny decleration.
I did the same thing when I first started using maven, almost everyone does :P
Related
I know what you'll think in the first place: "You should name your test classes with 'Test' in it etc."
But the problem is: it's already the case. I did scroll every possible SO post and didn't find anything, so no, unfortunately, this is not a duplicate.
I even have a test class named TestPleaseWillYouRunMyTest and a test method called testPleaseTest().
When I run a "mvn test", the "target/test-classes" folder is well populated, so I really don't understand why my tests aren't run...
Just in case it would help understand the problem, here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>SeleniumTests</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
</configuration>
</plugin>
</plugins>
<testSourceDirectory> src/test/java </testSourceDirectory>
</build>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
</dependencies>
</project>
Why you added testng, junit 4 and 5? first decide which testing framework you want to use
just to add my 5 cent to what khmarbaise said:
if your tests sit in standard directory you don't need to add testSourceDirectory at all, this tag is for non standard places.
Also you entry there is incorrect: src/test/java - this is definitely not the place where your test are.
mvn test
Only compiles the test classes but does not run the tests. In order to let the tests run use:
mvn verify
Please provide steps to how to install surefire plugin in Maven. I have googled and found no specific answer. There were lots of answer about the solution but no specific answer on how to install the plugin with steps.
Excpetion I am getting:
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#2f410acf
pom.xml i use :
<!-- language: xml --><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>au.com.simcentric</groupId>
<artifactId>Example20</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.14.0</version>
<type>jar</type>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.jexcelapi/jxl -->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.14.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.14.0</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1-hudson-3</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.14.0</version>
<type>jar</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hellojavaer/poi-excel-utils -->
<dependency>
<groupId>org.hellojavaer</groupId>
<artifactId>poi-excel-utils</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>2.1.13</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-java-commons</artifactId>
<version>2.0-BETA19</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
<version>2.44.0</version>
</dependency>
<dependency>
<groupId>com.opera</groupId>
<artifactId>operadriver</artifactId>
<scope>test</scope>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.14.0</version>
<type>jar</type>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx.version>3.0.0-milestone5</vertx.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
Referring to the attached pom.xml file, it is evident that inclusion of the surefire plugin is missing. Maven needs to know what plugin to include and which version. The following is suggested:
Add the Maven Surefire plugin entry in the pom.xml file
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>for example: 2.22.0</version>
</plugin>
</plugins>
</pluginManagement>
Then run mvn test
The usage example above has been extracted from here
Going a bit further, you can also include/exclude tests using the configuration schema
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>for example: 2.22.0</version>
<configuration>
<includes>
<include>IncludeTest.java</include>
</includes>
<excludes>
<exclude>ExcludeTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement></build>
A detailed instruction with examples is shown here.
Incase you would like surefire to hook to your testng.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin}</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
Upon success, the surefire plugin will generate a XML report at target/reports inside your project folder.
After so many researchers i have found the solution for my problem. in first place i thought there is a problem in my pom.xml file. but after make sure my pom.xml is correct i figure out system does not displays/recognized the maven in my machine. (mvn test) .
As the solution i followed below steps and now the system doesn't give me the exception i mentioned above in my question .
open cmd and type mvn test (in my case system didnt recognized the mvn)
Navigate to path > edit the system variables> Environment variables >select system variable- path
enter image description here
3.click on edit button and add the machine path which maven is available in to the end of the available path .
enter image description here
4.click ok
5.open cmd
6.type cmd test <>
7.now you can run your Maven project without the exception i have mentioned in my question :)
I have set up a maven project with Junit tests to run Selenium (java) scripts on our build server. From what I read Maven is meant to run any files specified in the folder test.java
With this in mind I set up my project with a TestAll class using#RunWith and #SuiteClasses to run specifically the classes and tests I wanted.
However, when I run mvn test maven runs all methods that have the keyword test anywhere in the title, ie Test_A_1423, all tests in a class with "Test" in the title and everything in any package with the keyword "Test". How do I run only the tests that I want or do I need to remove "Test" from any class or method I dont want to run. Included is my pom.xml file
`
<modelVersion>4.0.0</modelVersion>
<groupId>cyberx.automation</groupId>
<artifactId>tests</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cyberx.test.automation</name>
<url>http://maven.apache.org</url>
<!--<repositories>-->
<!--<repository>-->
<!--<id>central</id>-->
<!--<name>bintray</name>-->
<!--<url>http://jcenter.bintray.com</url>-->
<!--</repository>-->
<!--</repositories>-->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.testng</groupId>-->
<!--<artifactId>testng</artifactId>-->
<!--<version>6.9.4</version>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
`
You have regular expression to include/exclude tests.
See here for documentation of the surefire plugin.
I am building android application in which I have imported one of the maven library from this link https://github.com/devnied/EMV-NFC-Paycard-Enrollment.My project name is Nfcs and I have no errors in the project and I have added all of the dependencies in my project successfully but when I run the project error window opens saying "Your projects contains error please fix them before running".Please help me find out the error...
pom.xml of the library project.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>library</artifactId>
<packaging>jar</packaging>
<name>EMV paycard library</name>
<parent>
<groupId>com.github.devnied.emvnfccard</groupId>
<artifactId>parent</artifactId>
<version>1.1.1-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>com.github.devnied</groupId>
<artifactId>bit-lib4j</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- Unit test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
You error message says:
... Run Maven->Update Project or Use Quick Fix.
As you see the error is on your Maven Project, you should follow the hint Eclipse is giving you! And Right Click on your Maven Project > Maven > Update Project.
Usually, Eclipse hints are quite usefull.
Read this post to understand what this function is used for. You have to keep in mind that Maven is not the 'native' build manager in Eclipse and therefore needs a little adaptation and additional operations in order for it to work properly.
My mave don't want to compile sources. It shows that he can't find dependency classes.
Stack trace:
ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] \MAG\GIT\TechCamp-15\techcamp-15\src\main\java\pl\...\techcamp15\io\CsvWriterTest.java:[3,33] error: package org.fest.assertions does not exist
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Maven conventions specify that tests have to be placed under src/test/java not src/main/java
Test scoped dependencies are not available for files under src/main/java