Before talking about the issue, I want to explain something first.
I have a basic project with 4 files:
The project contains:
1.testbase01.java: contains information to preparing for initial parameter of testing like: get driver before testing...
2.test01.java: contains some tests and this class extends from testbase01.java
3.test01.xml: contains parameter for test file test01.java
4.pom.xml: contains where to store test report, which xml suite is called for testing, which listener is using...
The flow is:
I use 'mvn test' to run project
Test is run but the report is failed.
It cannot generate report to specified folder as I configured in pom.xml (timestamp).
I found that if I change the report folder to a fixed name (my report for example), it works.
Can you help me to fix this issue?
I dont know where to fix it.
Thank you
The issue is:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.8.2beta_20130330_0839 by Cédric Beust (cedric#beust.com)
...
LOCAL URL IS http://192.168.10.26:8000/enigma/candidate/index#candidates
NAME= Hoang
[TestNG] Reporter org.uncommons.reportng.JUnitXMLReporter#584534b2 failed
org.uncommons.reportng.ReportNGException: Failed generating JUnit XML report.
at org.uncommons.reportng.JUnitXMLReporter.generateReport(JUnitXMLReporter.java:83)
at org.testng.TestNG.generateReports(TestNG.java:1115)
at org.testng.TestNG.run(TestNG.java:1074)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:217)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:92)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
**Caused by: java.io.FileNotFoundException: D:\WORK\Workspace\bmp\test.reports\20131003-1346\xml\testsample.test01_results.xml (The system cannot find the path specified)**
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
at java.io.FileWriter.<init>(FileWriter.java:90)
at org.uncommons.reportng.AbstractReporter.generateFile(AbstractReporter.java:99)
at org.uncommons.reportng.JUnitXMLReporter.generateReport(JUnitXMLReporter.java:77)
... 8 more
[TestNG] Reporter org.uncommons.reportng.HTMLReporter#41ce5a9 failed
org.uncommons.reportng.ReportNGException: Failed generating HTML report.
This is my first test
This is my second test
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 20.441 sec - in TestSuite
at org.uncommons.reportng.HTMLReporter.generateReport(HTMLReporter.java:117)
at org.testng.TestNG.generateReports(TestNG.java:1115)
at org.testng.TestNG.run(TestNG.java:1074)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:217)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:84)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:92)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
Caused by: java.io.FileNotFoundException: D:\WORK\Workspace\bmp\test.reports\20131003-1346\html\index.html (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:212)
at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
at java.io.FileWriter.<init>(FileWriter.java:90)
at org.uncommons.reportng.AbstractReporter.generateFile(AbstractReporter.java:99)
at org.uncommons.reportng.HTMLReporter.createFrameset(HTMLReporter.java:129)
at org.uncommons.reportng.HTMLReporter.generateReport(HTMLReporter.java:104)
... 8 more
1.testbase01.java:
package common;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.ITestContext;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Parameters;
public class testbase01{
#Parameters({"localurl"})
#BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context, String localurl){
// get all UI controls
System.out.println("LOCAL URL IS "+localurl);
try
{
//init web driver
WebDriver driver = new FirefoxDriver();
driver.get(localurl);
// add driver into context. This is used for ScreenshotHTMLReporter
context.setAttribute("driver", driver);
}
catch (Exception ex)
{
Assert.assertTrue(false,ex.getMessage());
}
}
}
2.test01.java:
package testsample;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import common.TestBase;
import common.testbase01;
public class test01 extends testbase01 {
#Parameters({"user"})
#Test
public void getUser(String user)
{
System.out.println("NAME= " + user);
}
#Test
public void test01_no01()
{
System.out.println("This is my first test");
}
#Test
public void test01_no02()
{
System.out.println("This is my second test");
}
}
3.test01.xml:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="test01" verbose="3" parallel="false">
<parameter name="localurl" value="http://192.168.10.26:8000/enigma/candidate/index#candidates"/>
<test name="test01">
<parameter name="user" value="Hoang"/>
<classes>
<class name="testsample.test01"/>
</classes>
</test>
</suite>
4.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">
<modelVersion>4.0.0</modelVersion>
<groupId>BasicMavenProj</groupId>
<artifactId>bmp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<maven.build.timestamp.format>yyyyMMdd-HHmm</maven.build.timestamp.format>
<test.suite.dir>test.suites</test.suite.dir>
<test.report.dir>test.reports</test.report.dir>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.33.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.33.0</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.2</version>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${test.suite.dir}/test01.xml</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>${test.report.dir}/${timestamp}</reportsDirectory>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>
<!-- <value>com.validant.enigma3.reports.ScreenshotHTMLReporter,org.uncommons.reportng.JUnitXMLReporter</value>-->
</property>
</properties>
<systemPropertyVariables>
<test.screenshot.dir>${test.report.dir}/${timestamp}</test.screenshot.dir>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Did you try using ReportNG with default settings like described in this tutorial?I see some differences in your settings, so make that work for default settings and then you add your own configuration so you will what exactly caused your error.
One note - convention for naming Java classes is Camel Case with first letter in capital.
Related
My Camel route app detects other app's published ampq message(publishes numbers), but, fails to handle, with "no type converter available" error. How can I resolve?.
"org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.Integer to the required type: java.io.InputStream with value 79"
routebuilder class
package aaa.bbb.ccc.qscx;
import java.io.IOException;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.reactive.streams.api.CamelReactiveStreamsService;
import org.eclipse.microprofile.reactive.messaging.Incoming;
import org.reactivestreams.Subscriber;
#Startup
#ApplicationScoped
public class TheRoutes extends RouteBuilder {
#Inject
TheProcessor theProcessor;
#Inject
CamelContext ctx;
#Inject
CamelReactiveStreamsService crss;
#Override
public void configure() throws IOException, InterruptedException {
from("reactive-streams:in")
.process(theProcessor)
.log(".........from reactive-streams:in - body: ${body}");
}
#Incoming("prices")
public Subscriber<String> sink() {
return crss.subscriber("file:./target?fileName=values.txt&fileExist=append", String.class);
}
}
pom.xml
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb.ccc </groupId>
<artifactId>qscx</artifactId>
<version>1.0</version>
<properties>
<compiler-plugin.version>3.8.1</compiler-plugin.version>
<maven.compiler.parameters>true</maven.compiler.parameters>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus-plugin.version>1.0.0.CR2</quarkus-plugin.version>
<quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>1.0.0.CR2</quarkus.platform.version>
<surefire-plugin.version>2.22.1</surefire-plugin.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-timer</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-artemis-jms</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bean</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-streams-operators</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-support-common</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-camel</artifactId>
<version>1.0.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.26</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<systemProperties>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemProperties>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemProperties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
<name>qscx</name>
</project>
application.properties
amqp-username=quarkus
amqp-password=quarkus
mp.messaging.incoming.prices.address=prices
mp.messaging.incoming.prices.connector=smallrye-amqp
mp.messaging.incoming.prices.host=localhost
mp.messaging.incoming.prices.port=5672
mp.messaging.incoming.prices.username=quarkus
mp.messaging.incoming.prices.password=quarkus
mp.messaging.incoming.prices.broadcast=true
mp.messaging.incoming.prices.containerId=my-container-id
console stacktrace (excerpt)
2019-11-22 22:31:22,930 WARN [org.apa.cam.com.rea.str.ReactiveStreamsConsumer] (Camel (camel-1) thread #1 - reactive-streams://DCE85ACAC992C3A-0000000000000000) Error processing exchange. Exchange[DCE85ACAC992C3A-000000000000005F]. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - Cannot store file: .\target\values.txt]: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot store file: .\target\values.txt
at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:376)
at org.apache.camel.component.file.GenericFileProducer.writeFile(GenericFileProducer.java:300)
at org.apache.camel.component.file.GenericFileProducer.processExchange(GenericFileProducer.java:164)
at org.apache.camel.component.file.GenericFileProducer.process(GenericFileProducer.java:75)
at org.apache.camel.support.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:67)
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:134)
at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$RedeliveryState.run(RedeliveryErrorHandler.java:476)
at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:185)
at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:59)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:87)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:228)
at org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer.lambda$doSend$3(ReactiveStreamsConsumer.java:96)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: 79 of type: java.lang.Integer on: Message[]. Caused by: No type converter available to convert from type: java.lang.Integer to the required type: java.io.InputStream with value 79. Exchange[DCE85ACAC992C3A-000000000000005F]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: java.lang.Integer to the required type: java.io.InputStream with value 79]
at org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:115)
at org.apache.camel.component.file.FileOperations.storeFile(FileOperations.java:355)
... 14 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.Integer to the required type: java.io.InputStream with value 79
at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:139)
at org.apache.camel.support.MessageSupport.getMandatoryBody(MessageSupport.java:113)
... 15 more
other notes
publishing app is based upon the Quark Ampq example:
https://github.com/quarkusio/quarkus-quickstarts/tree/master/amqp-quickstart/src/main/java/org/acme/quarkus/sample
technologies
java 8
quarkus
smallrye
camel
maven
It seems the subscriber does not currently execute the type conversion. It may be solved in a future release.
In the meantime, you need to enforce it in the route:
#Override
public void configure() throws IOException, InterruptedException {
from("direct:proc")
.convertBodyTo(String.class)
.to("file:./target?fileName=values.txt&fileExist=append");
}
#Incoming("prices")
public Subscriber<String> sink() {
return crss.subscriber("direct:proc", String.class);
}
I have below feature files (Separate feature files) in src/test/resources/feature/ and I would like to run them in parallel. Like: One feature file has to execute in chrome and another one has to execute in another chrome instance as mentioned #Tags name.
#Regression
Scenario: Searching for HelpMate on Company Hompe page
Given I navigate to application URL
Then I verified title "Company - Production - Sign In" on Login Page
after
launched the URL
When I type username as "defined in config" in username filed on Login
page
And I type password as "defined in config" in password filed on Login
page
And I click Login button on Login page
And I wait for 15 seconds
Then I verified title "Company - Production - My Applications" on
Login Page
#Regression
Scenario Outline: Searching for different options on Company Home
page
Given I navigate to application URL
Then I verified title "Company - Production - Sign In" on Login Page
after launched the URL
When I type username as "defined in config" in username filed on Login
page
And I type password as "defined in config" in password filed on Login
page
And I click Login button on Login page
And I wait for 15 seconds
I'm using cucumber-java 1.2.5 version, and AbstractTestNGCucumberTests as runner. I'm able to run a single feature file but when i try to run 2 feature files using cucumber-jvm-parallel-plugin v#4.0.0 and maven surefire plugin v#2.40, it is not initialing the test class
(Error:cucumber.runtime.CucumberException: cucumber.runtime.CucumberException: Failed to instantiate class com.cvs.stepdefinition.LoginPage)
This error is gone after I used updated cucumber dependencies
cucumber-jvm-parallel-plugin-- Not using anymore as it is not required with latest version of cucumber libraries
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>4.0.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>validate</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>
<pakage>com.cvs.stepdefinition</pakage>
</glue>
<featuresDirectory>src/test/resources/features
</featuresDirectory>
<cucumberOutputDir>${project.build.directory}/
cucumberparallel</cucumberOutputDir>
<format>json,html</format>
<testFailureIgnore>true</testFailureIgnore>
<tags>
<tag>#Regression</tag>
</tags>
</configuration>
</execution>
</executions>
</plugin>
maven-surefire-plugin--UPDATED
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
TestNG.xml--UPDATED
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng Cucumber Suite" parallel="tests"configfailurepolicy="continue" thread-count="2">
<test name="SmokeSuite">
<parameter name="browserName" value="chrome"/>
<classes>
<class name="com.cvs.runner.TestSuiteRunner"></class>
</classes>
</test>
</suite>
I have tried overriding the method from AbstractTestNGCucumberTests and set the parallel attribute in #DataProvider annotation to true but still getting the same error.
#DataProvider(parallel=true)
public Object[][] features() {
return testNGCucumberRunner.provideFeatures();
}
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">
<modelVersion>4.0.0</modelVersion>
<groupId>testNewBDD</groupId>
<artifactId>TestAutomation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>TestAutomation</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<mainClass>ReportGenerator</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.6</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.0</version>
</dependency>
</dependencies>
</project>
Runner
#CucumberOptions(
strict = true,
monochrome = true,
features = {"src/test/resources/features"},
tags={"#Regression"},
glue = {"stepDef", "utils"},
plugin = {"pretty", "html:target/cucumber-html-report","json:target/cucumber-html-report/TestHomePage.json"},
//junit ={ "--step-notifications"},
dryRun = false
)
public class UITest {
private TestNGCucumberRunner testNGCucumberRunner;
#BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
#Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "scenarios")
public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper cucumberFeature) throws Throwable {
testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
}
#DataProvider(parallel=true)
public Object[][] scenarios() {
return testNGCucumberRunner.provideScenarios();
}
#AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
testNGCucumberRunner.finish();
}
}
There is only one feature file having 2 scenarios and i want these 2 scenarios to run on two different browser parallely. Please help me to resolve this.
Key Point : We would request you to use Cucumber-JVM v4.x.x specially to implement parallel execution without using cucumber-jvm-parallel-plugin as you are using pretty old dependency(v1.2.5) of Cucumber.
Note : In below implementation, we would be reading browser parameter from TestNG.xml file
First - Update POM.xml with correct set of io.cucumber dependencies as per any cucumber v >= 4.0.0 lets pick v4.2.6
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.6</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.6</version>
</dependency>
Second - Customize TestNGRunner class as per your framework need
package com.jacksparrow.automation.suite.runner;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import com.jacksparrow.automation.steps_definitions.functional.BaseSteps;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
#CucumberOptions(features = "classpath:features/functional/",
glue = {"com.jacksparrow.automation.steps_definitions.functional" },
plugin = { "pretty","json:target/cucumber-json/cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml", "html:target/cucumber-reports"},
tags = { "#BAMS_Submitted_State_Guest_User" },
junit ={ "--step-notifications"},
strict = false,
dryRun = false,
monochrome = true)
public class RunCukeTest extends Hooks {
}
Third - Implement Hooks.java
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import cucumber.api.testng.AbstractTestNGCucumberTests;
public class Hooks extends AbstractTestNGCucumberTests {
#Parameters({ "browser" })
#BeforeTest
public void setUpScenario(String browser){
//BaseSteps.getInstance().getBrowserInstantiation(browser); your browser setup method
}
}
Fourth - Update TestNG.xml under /src/test/resources/ as per your TestNGRunner Class and framework need.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng Cucumber Suite" parallel="tests" thread-count="2">
<test name="SmokeTest">
<parameter name="browser" value="chrome" />
<classes>
<class name="com.cvs.runner.TestSuiteRunner" />
</classes>
</test>
</suite>
Fifth - You shall be all set to run automation suite using TestNG in any of the following ways
- Run TestNG.xml directly from IDE
- From CMD - mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng.xml
- From POM.xml - Using Surefire Plugin
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Did you try to add number of treads in your .xml file, I do have it in mine.
So your .xml file will be:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testng Cucumber Suite" parallel="tests" thread-count="2">
<test name="SmokeSuite">
<classes>
<class name="com.cvs.runner.TestSuiteRunner"></class>
</classes>
</test>
</suite>
(Also try to change parallel = "tests" to parallel methods. And if you r using priorities in your tests parallel running is not gonna work)
Cucumber 4 provides native support to run scenarios(not by features) in parallel.
you have to update your pom.xml dependencies to latest cucumber version.
cucumber-core 4.2.0, cucumber-java 4.2.0, cucumber-junit 4.2.0
In the runner file, you have add "--thread 2 " like a plugin. this will run the scenario in 2 threads.
I have a very simple JPA project. This is my directory layout..
/src
/main
/java
/biz
/tugay
/jpaExamples
App.java
/model
Person.java
/resources
/META-INF
persistence.xml
So it is pretty standard maven directory layout. This is my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>biz.tugay</groupId>
<artifactId>jpa-examples</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>jpa-examples</name>
<url>http://www.tugay.biz</url>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>2.4.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-persistence</artifactId>
<version>2.4.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
</dependency>
</dependencies>
<build>
<finalName>bare-maven-project</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>biz.tugay.jpaExamples.App</mainClass>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
and persistence.xml
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="jpaExamples" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>biz.tugay.jpaExamples.model.Person</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:~/sampleh2db;TRACE_LEVEL_FILE=0"/>
<property name="javax.persistence.jdbc.user" value="test"/>
<property name="javax.persistence.jdbc.password" value="test"/>
<property name="openjpa.Log" value="DefaultLevel=ERROR, Tool=ERROR"/>
</properties>
</persistence-unit>
Finally, App.java
package biz.tugay.jpaExamples;
import biz.tugay.jpaExamples.model.Person;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import java.sql.*;
public class App {
private static final String PERSISTENCE_UNIT_NAME = "jpaExamples";
private static final EntityManagerFactory ENTITY_MANAGER_FACTORY = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
public static void main(String[] args) throws ClassNotFoundException, SQLException {
final EntityManager entityManager = ENTITY_MANAGER_FACTORY.createEntityManager();
final Person person = entityManager.find(Person.class, 1L);
System.out.println(person);
entityManager.close();
ENTITY_MANAGER_FACTORY.close();
}
}
When I execute App.java from IntelliJ, all is fine. I will see the output:
Person{id=1, firstname='Koray', lastname='Tugay', address='Yıldız Cd. 43 / 30', city='İstanbul'}
This is what IntelliJ generates, when running main in App.java
"C:\Program Files\Java\jdk1.8.0_121\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_121\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_121\jre\lib\rt.jar;C:\Users\Koray Tugay\Desktop\jpa-examples\target\classes;C:\Users\Koray Tugay\.m2\repository\org\eclipse\persistence\javax.persistence\2.1.1\javax.persistence-2.1.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa\2.4.2\openjpa-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\commons-lang\commons-lang\2.6\commons-lang-2.6.jar;C:\Users\Koray Tugay\.m2\repository\commons-collections\commons-collections\3.2.2\commons-collections-3.2.2.jar;C:\Users\Koray Tugay\.m2\repository\net\sourceforge\serp\serp\1.15.1\serp-1.15.1.jar;C:\Users\Koray Tugay\.m2\repository\junit\junit\3.8.1\junit-3.8.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\geronimo\specs\geronimo-jms_1.1_spec\1.1.1\geronimo-jms_1.1_spec-1.1.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\geronimo\specs\geronimo-jta_1.1_spec\1.1.1\geronimo-jta_1.1_spec-1.1.1.jar;C:\Users\Koray Tugay\.m2\repository\commons-pool\commons-pool\1.6\commons-pool-1.6.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\xbean\xbean-asm5-shaded\3.17\xbean-asm5-shaded-3.17.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\geronimo\specs\geronimo-jpa_2.0_spec\1.1\geronimo-jpa_2.0_spec-1.1.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa-persistence\2.4.2\openjpa-persistence-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa-kernel\2.4.2\openjpa-kernel-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\org\apache\openjpa\openjpa-lib\2.4.2\openjpa-lib-2.4.2.jar;C:\Users\Koray Tugay\.m2\repository\com\h2database\h2\1.4.192\h2-1.4.192.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain biz.tugay.jpaExamples.App
so I am pretty sure everything related to my persistence.xml configuration and dependencies are fine..
When I try mvn exec:java (after mvn clean install) I get:
[WARNING]
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:745)
Caused by: <openjpa-2.4.2-r422266:1777108 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
biz.tugay.jpaExamples.model.Person".
at org.apache.openjpa.enhance.ManagedClassSubclasser.prepareUnenhancedClasses(ManagedClassSubclasser.java:115)
at org.apache.openjpa.kernel.AbstractBrokerFactory.loadPersistentTypes(AbstractBrokerFactory.java:311)
at org.apache.openjpa.kernel.AbstractBrokerFactory.initializeBroker(AbstractBrokerFactory.java:235)
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:211)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:154)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:226)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:153)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:59)
at biz.tugay.jpaExamples.App.main(App.java:16)
... 6 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.240 s
[INFO] Finished at: 2017-05-24T22:32:46+03:00
[INFO] Final Memory: 11M/139M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project jpa-examples: An exception occured while executing the Java class. null: InvocationTargetException: This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "
[ERROR] biz.tugay.jpaExamples.model.Person".
How do I fix this? I think somehow OpenJPA is unable to find persistence.xml, but I can verify that it is found under target/classes.
Adding this to pom.xml worked:
<plugin>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<includes>**/model/*.class</includes>
<excludes>**/model/XML*.class</excludes>
<addDefaultConstructor>true</addDefaultConstructor>
<enforcePropertyRestrictions>true</enforcePropertyRestrictions>
</configuration>
<executions>
<execution>
<id>enhancer</id>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<!-- set the version to be the same as the level in your runtime -->
<version>2.4.2</version>
</dependency>
</dependencies>
</plugin>
I'm trying to use apache tika on top of Spark. However, i'm having issues with configuration. My best guess at the moment is that the dependencies (of which tika has a lot...) are not bundled with the JAR for spark.
If this intuition is correct I am unsure what the best path forward is. But i am also not certain that that is even my issue.
The following is a pretty simple spark job which compiles but hits a runtime error when it gets to the Tika instantiation.
My pom.xml is as follows:
<project>
<groupId>tika.test</groupId>
<artifactId>tikaTime</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>TikaTime</name>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
</project>
My sample code is here:
/* TikaTime.java */
import org.apache.spark.api.java.*;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.function.Function;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.File;
import java.io.IOException;
import org.apache.tika.*;
public class TikaTime {
public static void main(String[] args) throws IOException {
String logFile = "file.txt";
File logfile = new File("/home/file.txt");
SparkConf conf = new SparkConf().setAppName("TikaTime");
JavaSparkContext sc = new JavaSparkContext(conf);
JavaRDD<String> logData = sc.textFile(logFile).cache();
long numAs = logData.filter(new Function<String, Boolean>() {
public Boolean call(String s) { return s.contains("a"); }
}).count();
long numBs = logData.filter(new Function<String, Boolean>() {
public Boolean call(String s) { return s.contains("b"); }
}).count();
System.out.println("Lines with a: " + numAs + ", lines with b: " + numBs);
//Tika facade class.
Tika tika = new Tika();
}
}
Stack Trace of Error is as follows:
Lines with a: 2, lines with b: 1
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tika/Tika
at TikaTime.main(TikaTime.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:672)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.tika.Tika
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 10 more
Curious if others have encountered this issue before. I rarely use Maven and am also somewhat new to Spark, so I'm not confident my intuition is correct on this.
Edit: Including my spark submit syntax incase it is of interest.
~/spark151/spark-1.5.1/bin/spark-submit --class "TikaTime" --master local[4] target/tikaTime-1.0.jar
Per Gagravarr's response and my original suspicion, the issue was needing to provide the uber-jar to Spark. This was accomplished using the maven-shade plugin. New pom.xml shown below.
<project>
<groupId>tika.test</groupId>
<artifactId>tikaTime</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>TikaTime</name>
<packaging>jar</packaging>
<version>1.0</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.11</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<finalName>uber-${project.artifactId}-${project.version}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>
Note: you must also submit the uber-jar created from this to spark instead of the original.
I am new to TestNg. I am trying to test one sample hello world program.
Following is my project structure
Source Package
com.mycompany.mavenproject1 =>HelloWorld.java
Test Package
com.test => NewTestConfig.java & NewTestNGTest.java
Helloworld.java
package com.mycompany.mavenproject1;
public class HelloWorld {
String msg = "test";
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
NewTestConfig.java
package com.test;
import com.mycompany.mavenproject1.HelloWorld;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
public class NewTestConfig {
#Bean
public HelloWorld helloWorldBean() {
HelloWorld hw = new HelloWorld();
return hw;
}
}
NewTestNGTest.java
package com.test;
import com.mycompany.mavenproject1.HelloWorld;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.springframework.test.context.ContextConfiguration;
#Test
#ContextConfiguration(classes={ NewTestConfig.class })
public class NewTestNGTest {
#Autowired
HelloWorld hw ;
#Test
public void exampleOfTestNgMaven() {
String s = hw.getMsg();
System.out.println("This is TestNG-Maven Example" + s);
}
#BeforeClass
public static void setUpClass() throws Exception {
}
#AfterClass
public static void tearDownClass() throws Exception {
}
#BeforeMethod
public void setUpMethod() throws Exception {
}
#AfterMethod
public void tearDownMethod() throws Exception {
}
}
My pom.xml looks like below:
<?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>com.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>mavenproject1</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I try to run the test I get NullpointerException (at hw.getMsg();)
Error stack:
Test set: com.test.NewTestNGTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.209 sec <<< FAILURE!
exampleOfTestNgMaven(com.test.NewTestNGTest) Time elapsed: 0.003 sec <<< FAILURE!
java.lang.NullPointerException
at com.test.NewTestNGTest.exampleOfTestNgMaven(NewTestNGTest.java:25)
I tried to run test in debug mode, I always get HelloWorld bean as null. So eventually test fails due to NullPointerException. I tried many other variations such as instead of config class tried using applicationContext.xml but my bean never gets injected.
For last 2 days I am struggling to make simple test pass but unable to figure out what's going wrong. Why my context is not getting loaded for test?
Any help is greatly appreciated.
Thanks
Manisha