I'm trying to run a simple test with Firefox, using Serenity.
This 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>serenity.test</groupId>
<artifactId>firefox</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<serenity.version>1.4.0</serenity.version>
<serenity.maven.version>1.4.0</serenity.maven.version>
<webdriver.driver>firefox</webdriver.driver>
<surefire.rerunFailingTestsCount>0</surefire.rerunFailingTestsCount>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<configuration>
<includes>
<include>**/features/**/*.java</include>
</includes>
<systemProperties>
<webdriver.driver>${webdriver.driver}</webdriver.driver>
<surefire.rerunFailingTestsCount>${surefire.rerunFailingTestsCount}</surefire.rerunFailingTestsCount>
</systemProperties>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-webdriver</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.18</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And this is my test class:
public class FirefoxTest {
#Managed
WebDriver driver;
private Actor actor;
#Before
public void setup(){
actor = Actor.named("Firefox user");
actor.can(BrowseTheWeb.with(driver));
}
#Test
public void open_browser(){
actor.attemptsTo(Open.url("www.google.com"));
}
}
Running "mvn verify" I get the following log:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building firefox 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # firefox ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # firefox ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # firefox ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\work\verso3\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # firefox ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.20:test (default-test) # firefox ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running features.FirefoxTest
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.629 s <<< FAILURE! - in features.FirefoxTest
[ERROR] open_browser(features.FirefoxTest) Time elapsed: 0.58 s <<< ERROR!
java.lang.NullPointerException
at features.FirefoxTest.open_browser(FirefoxTest.java:31)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] FirefoxTest.open_browser:31 ยป NullPointer
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[ERROR] There are test failures.
Please refer to C:\work\verso3\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # firefox ---
[INFO] Building jar: C:\work\verso3\target\firefox-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- serenity-maven-plugin:1.4.0:aggregate (serenity-reports) # firefox ---
[INFO] current_project.base.dir: C:\work\verso3
[INFO] Generating test results for 0 tests
[INFO] 0 requirements loaded after 27 ms
[INFO] 0 related requirements found after 27 ms
[INFO] Generating test outcome reports: false
[INFO] Starting generating reports: 38 ms
[INFO] Configured report threads: 80
[INFO] Finished generating test results for 0 tests after 316 ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.337 s
[INFO] Finished at: 2017-06-08T13:20:18+03:00
[INFO] Final Memory: 17M/274M
[INFO] ------------------------------------------------------------------------
Process finished with exit code 0
So what's going on here? Why am I getting that null pointer exception? What am I doing wrong here?
The Firefox version I'm using is 53.0.3 (64-bit).
It is probably an incompatible version of Firefox or gecko. But why are you managing the WebDriver instance yourself?
Related
I setup simple Spring Boot project to serve basic HTML pages. I wrote a kind of integration tests with testNG. Now, I want to run my tests with maven does not see my tests.
STR:
Run mvn spring-boot:run
Run mvn test
Output:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------------< vznd:selenium >----------------------------
[INFO] Building selenium 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) # selenium ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 0 resource
[INFO] Copying 27 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # selenium ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) # selenium ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] skip non existing resourceDirectory C:\Users\vladyslav.kovalenko\OneDrive - FORM.com\Documents\den\selenium-webdriver-tests\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # selenium ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M6:test (default-test) # selenium ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.963 s
[INFO] Finished at: 2022-05-09T13:03:51+01:00
[INFO] ------------------------------------------------------------------------
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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>vznd</groupId>
<artifactId>selenium</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
<testng.version>7.5</testng.version>
<selenium-java.version>3.141.59</selenium-java.version>
<commons-io.version>2.11.0</commons-io.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium-java.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>/tmp/chromedriver/chromedriver</webdriver.chrome.driver>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
testng.xml:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="SeleniumApp Tests" parallel="false">
<test name="Selenium Test">
<classes>
<class name="vznd.selenium.AlertsControllerTest"/>
<class name="vznd.selenium.GettingBrowserInformationTest"/>
<class name="vznd.selenium.FramesTest"/>
<class name="vznd.selenium.BrowserNavigationTest"/>
<class name="vznd.selenium.KeyboardActionsTest"/>
<class name="vznd.selenium.WindowsTest"/>
</classes>
</test>
</suite>
Test example:
package vznd.selenium;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class FramesTest extends BaseTest {
#BeforeMethod
public void openPageWithIframes() {
driver.get(HTMLPath.FRAMES);
}
#Test
public void switchToFrameUsingWebElement() {
WebElement greenFrame = driver.findElement(By.id("first-iframe"));
driver.switchTo().frame(greenFrame);
WebElement table = driver.findElement(By.cssSelector("table[id='green-table']"));
Assert.assertNotNull(table, "The table WebElement object was null!");
}
}
Spring Boot Application:
package vznd.selenium;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class SeleniumApp {
public static void main(String[] args) {
SpringApplication.run(SeleniumApp.class, args);
}
}
Controller example:
package vznd.selenium.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
#Controller
public class FramesController {
#GetMapping("/iframes")
public String iframes() {
return "iframes";
}
}
I tried to google about similar problems, but most answers is about naming test classes with *Test suffix and that is not my case.
The tests are executed in IDEA by right-click on the project -> Run -> All tests.
Please, advice me how I can get tests executed with maven.
If you see the logs surefire is not detecting TestNG.
Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
If you remove SpringBoot will be: Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
Try adding TestNG dependency to surefire plugin:
<project>
...
<dependencies>
...
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<webdriver.chrome.driver>/tmp/chromedriver/chromedriver</webdriver.chrome.driver>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>3.0.0-M5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
I was trying to run maven project for my automation script using selenium/java. However, the tests are not getting run when I executed mvn test command. Please let me know what could be the issue that the cucumber tests are not getting executed when I try to run maven Project.
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< KSAEpic3MavenProj:KSAEpic3 >---------------------
[INFO] Building KSAEpic3 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # KSAEpic3 -
--
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # KSAEpic3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # KS
AEpic3 ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # KSAEpic
3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # KSAEpic3 ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.628 s
[INFO] Finished at: 2018-07-26T08:57:14+04:00
[INFO] ------------------------------------------------------------------------
Below is my POM.XML file
<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>KSAEpic3MavenProj</groupId>
<artifactId>KSAEpic3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>KSAEpic3</name>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope> </dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.23</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>bson</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>ojdbc14</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</dependency>
</dependencies>
</project>
Log when run from IDE -
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building KSAEpic3 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # KSAEpic3 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # KSAEpic3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # KSAEpic3 ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # KSAEpic3 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) # KSAEpic3 ---
[INFO] Surefire report directory: D:\Maven WorkSpace\KSAEpic3\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.751s
[INFO] Finished at: Thu Jul 26 09:41:48 GST 2018
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------
Runner Class
package testrunner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
#CucumberOptions(
plugin={"pretty", "html:target/cucumber", "json:target/JSON/Output.json"},
features={"D:/KSA-Online Banking-AutomationFramework/Epic2Maven/src/test/resources/features"},
// plugin={"com.cucumber.listener.ExtentCucumberFormatter:"},
tags={"#SI_TransferBtwAccounts"},
glue={"stepdefinition"}
)
public class Epic2TestRunner {
}
Feature File -
#SI_TransferBtwAccounts
Feature: Verify that SI is setup successfully Between the accounts and record is inserted in DB
Scenario: Verify that SI is setup successfully between the accounts
Given When browser is launched and KSA URL is loaded
When STAFFUser1 logins to application
When Password is entered
When clicked on Login button
When clicks on Pay&Transfer Icon
When clicks on Transfer link
When clicks on StandingInstruction link
When selects TransferBtwAccount option
When enters Trnsfrbtwaccamount in the field
When FromandToDate are captured
When Terms&Conditions are checked
When clicked on continue button
When StartandEnd Dates are verified in pre-confirmation screen
When Entered OTP
When clicked on Confirm button
When Captured the Reference number
When Record is displayed in StandingInstruction DB
When record is displayed in the Standing Instruction menu
Then user should be logged out of application.
StepDefinition file -
public class Transfer_SI_BtwAccounts extends Browser_Initialization {
private static String FromDate , ToDate, SIRefnum, refnumber, PurposeofTransferText, amount;
#When("^STAFFUser(\\d+) logins to application$")
public void staffuser_logins_to_application(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
try {
c_InputText("KSAOnlineBanking_Login_Username", GetPropertValue("StaffUssername"));
} catch (Exception e ) {
Assert.fail("unable to enter username");
}
}
#When("^selects TransferBtwAccount option$")
public void selects_TransferBtwAccount_option() throws Throwable {
// Write code here that turns the phrase above into concrete actions
try {
Thread.sleep(10000);
c_click("TransferList");
c_click("SI-BTWACC");
} catch (Exception e ) {
Assert.fail("unable to select option");
}
}
#When("^enters Trnsfrbtwaccamount in the field$")
public void enters_Trnsfrbtwaccamount_in_the_field() throws Throwable {
// Write code here that turns the phrase above into concrete actions
try {
Thread.sleep(6000);
c_InputText("TBTWACCAmountField",GetPropertValue("EnterAmount"));
} catch (Exception e ) {
e.printStackTrace();
}
}
The name of the test class is important, if not specified explicitely.
By default, the Surefire Plugin will automatically include all test classes with the following wildcard patterns:
"**/Test*.java" - includes all of its subdirectories and all Java filenames that start with "Test".
"**/*Test.java" - includes all of its subdirectories and all Java filenames that end with "Test".
"**/*Tests.java" - includes all of its subdirectories and all Java filenames that end with "Tests".
"**/*TestCase.java" - includes all of its subdirectories and all Java filenames that end with "TestCase".
Your class is named Epic2TestRunner.java so it is not recognized by default. Renaming it to TestEpic2Runner.java or Epic2RunnerTest.java would be a possible solution.
Despite apparently this post showed a solution to using powermock and jacoco, I haven't been able to make it work in a pretty simple project (available on GitHub).
In my case, the test executes correctly but the jacoco.exec file is missing so jacoco doesn't check coverage.
Test class:
#RunWith(PowerMockRunner.class)
#PrepareOnlyThisForTest(Util.class)
#PowerMockIgnore("org.jacoco.agent.rt.*")
public class UtilTest {
#Test
public void testSay() throws Exception {
PowerMockito.mockStatic(Util.class);
Mockito.when(Util.say(Mockito.anyString())).thenReturn("hello:mandy");
Assert.assertEquals("hello:mandy", Util.say("sid"));
}
}
Util.java
public class Util {
private Util() {}
public static String say(String s) {
return "hello:"+s;
}
}
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>com.codependent.jacocopower</groupId>
<artifactId>jacoco-powermock</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<powermock.version>1.5.4</powermock.version>
<jacoco.version>0.7.4.201502262128</jacoco.version>
</properties>
</project>
Maven execution trace, complaining that no jacoco.exec file was found:
>> mvn clean verify
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jacoco-powermock 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # jacoco-powermock ---
[INFO] Deleting C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # jacoco-powermock ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # jacoco-powermock ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target\classes
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:instrument (default-instrument) # jacoco-powermock ---
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # jacoco-powermock ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # jacoco-powermock ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) # jacoco-powermock ---
[INFO] Surefire report directory: C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.codependent.jacoco.UtilTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.239 sec - in com.codependent.jacoco.UtilTest
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:restore-instrumented-classes (default-restore-instrumented-classes) # jacoco-powermock ---
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (default-report) # jacoco-powermock ---
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target\jacoco.exec
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # jacoco-powermock ---
[INFO] Building jar: C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target\jacoco-powermock-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- jacoco-maven-plugin:0.7.4.201502262128:check (default-check) # jacoco-powermock ---
[INFO] Skipping JaCoCo execution due to missing execution data file:C:\SoftDesarrollo\6-Workspaces\libertyGecon\jacoco-powermock\target\jacoco.exec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.987s
[INFO] Finished at: Thu Jan 21 09:13:55 CET 2016
[INFO] Final Memory: 23M/331M
[INFO] ------------------------------------------------------------------------
UPDATE: (here on GitHub)
With the answer provided by Lencalot the jacoco.exec file is generated but the following scenario keeps saying that the ServiceImpl class coverage is 0%:
ServiceImpl
public class ServiceImpl implements Service{
public String operation() {
return Util.say("Hi!");
}
}
ServiceTest
#RunWith(PowerMockRunner.class)
#PrepareForTest({Util.class})
public class ServiceTest {
private Service service = new ServiceImpl();
#Test
public void testOperation() throws Exception {
PowerMockito.mockStatic(Util.class);
Mockito.when(Util.say(Mockito.anyString())).thenReturn("Bye!");
Assert.assertEquals("Bye!", service.operation());
}
}
Trace:
[WARNING] Rule violated for class com.codependent.jacoco.ServiceImpl: lines covered ratio is 0.00, but expected minimum is 0.50
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<append>true</append>
</configuration>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<includes>
<include>**/*test*</include>
</includes>
</configuration>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
<configuration>
<includes>
<include>**/*test*</include>
</includes>
</configuration>
</execution>
<execution>
<id>Prepare-Jacoco</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*test*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
you can remove Check for now, we can try to get it working with out that first.
Update your Jacoco dependency to look like this
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
Make you maven surefire plugin look like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
in your properties section Add this as, and change your jacoco Version:
<jacoco.version>0.7.5.201505241946</jacoco.version>
<jacoco.outputDir>${project.basedir}/target/jacoco.exec</jacoco.outputDir>
#codependent Heres an example of why you want to mock.
Lets assume your Util.class has a lot more code, a lot of instantiations and maybe it even touches some server side stuff, hell maybe even its a UI. You don't want to instantiate User.class just to test a single method in some other class called UtilUser.class
protected class UtilUser {
protected UtilUser() {}
public Boolean checkSay(String s) {
String expectedString = "hello:" + s;
String actualString = Util.say(s);
if (expectedString.equals(actualString){
return true;
} else {
return false;
}
}
}
To unit test UtilUser, you want to hit all branches. So in your test you would mock the Util.class, and in one unit test force it to return the correct string, and in another test have it return an incorrect string. You don't care about testing User.class, you know it will behave accordingly or you will have another test to take care of that. For unit testing UtilUser, you can expect Util to either return a correct string or an incorrect string, and you want to test both possibilities.
Theres a time and a place for mocks and they are a great tool to know, but DO NOT think they should be used often. Please refer to the following article, it will give you good insight into when you should use mocks: When To Mock
I have been having trouble getting my SCR plugin working. I have searched as much as I could bur only found examples that were not similar to the structure I am required to use. Snippets of POMs below. These are pretty much the default generated by the CQ project archetype. All dependencies are there, so it is probably not that. Here is the output of the build:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project Bundle 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) # project-bundle ---
[INFO] Deleting C:\project-path\target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # bundle ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\project-path\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # project-bundle ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 4 source files to C:\project-path\target\classes
[INFO]
[INFO] --- maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) # project-bundle ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # project-bundle ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\project-path\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # project-bundle ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:9c6abc2:test (default-test) # project-bundle ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-bundle-plugin:2.3.6:bundle (default-bundle) # project-bundle ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # project-bundle ---
[INFO] Installing C:\project-path\target\project-bundle-1.0-SNAPSHOT.jar to C:\user-path\.m2\repository\com\project\cq\project-bundle\1.0-SNAPSHOT\project-bundle-1.0-SNAPSHOT.jar
[INFO] Installing C:\project-path\pom.xml to C:\user-path\.m2\repository\com\project\cq\project-bundle\1.0-SNAPSHOT\project-bundle-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-bundle-plugin:2.3.6:install (default-install) # project-bundle ---
[INFO] Installing com/project/cq/project-bundle/1.0-SNAPSHOT/project-bundle-1.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.189s
[INFO] Finished at: Wed Apr 17 10:29:17 CDT 2013
[INFO] Final Memory: 15M/221M
[INFO] ------------------------------------------------------------------------
The key part of the output is the [INFO] --- maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) # project-bundle ---. It appears that it is not generating anything even though the annotations exist on the class.
Parent POM Snippet:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.7.4</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.6</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- use version 2.3.2 to have java 1.5 as the default -->
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<version>2.3.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<version>2.0.6</version>
</plugin>
<plugin>
<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>
<version>0.0.13</version>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the
Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<versionRange>[1.7.4,)</versionRange>
<goals>
<goal>scr</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Child POM Snippet:
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>generate-scr-descriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>project.project-bundle</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.sling</groupId>
<artifactId>maven-sling-plugin</artifactId>
<configuration>
<slingUrl>http://${crx.host}:${crx.port}/apps/project/install</slingUrl>
<usePut>true</usePut>
</configuration>
</plugin>
</plugins>
</build>
Code being built:
package com.project.cq.examples.dictionaryservice.impl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import com.project.cq.examples.dictionaryservice.DictionaryService;
#Component(immediate = true, metatype = true, label = "Service Implementation", description = "The implementation for the Service")
#Service
public class DictionaryServiceServletImpl implements DictionaryService {
#Property(label = "Words", description = "The list of words.")
private static final String PROP_WORDS = "words";
// The set of words
private String[] words;
private boolean active;
private boolean modified;
#Override
public boolean checkWord(String word) {
word = word.toLowerCase();
// This is very inefficient
for (int i = 0; i < words.length; i++) {
if (words[i].equals(word)) {
return false;
}
}
return true;
}
protected void activate(ComponentContext context) {
active = true;
dictionary = (String[]) context.getProperties().get(
PROP_WORDS);
}
protected void deactivate(ComponentContext context) {
dictionary = null;
active = false;
}
protected void modified(ComponentContext context) {
modified = true;
dictionary = (String[]) context.getProperties().get(
PROP_WORDS);
}
}
Any help is greatly appreciated.
I'm guessing you're using <packaging>bundle</packaging>, if so I got this working by upgrading maven-scr-plugin to 1.9.0, with org.apache.felix.scr.annotations # 1.7.0
I put a tarball of a working version here: https://dl.dropboxusercontent.com/u/2465717/com.stackoverflow.osgi.scr.tgz
Note: you can enable the Eclipse m2e lifecycle mapping - it works well (Juno SR2), generating SCR component errors in the normal Problems console. Change the action <ignore/> to:
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
Also while the spec indicates the SCR runtime will search for overloaded de/activate methods - as personal preference I would use #Activate, #Deactive and #Modified on the respective methods to make the intent explicit (in code and generated XML). But each to their own.
I suggest that you
upgrade to the latest version of the maven-scr-plugin
generate debug with -X, e.g. mvn -X compile
Upgrading to 1.9.0 worked for me. Are we saying plugin v1.7.4 does not generate descriptors. Why would it be so, isn't that the core task of maven-scr-plugin.
I am stuck very badly in a very simple implementation of an Arquillian test case. I followed Can I add jars to maven 2 build classpath without installing them? to add my project jars to maven repository. I am using Glassfish server as my application server.
Then I need to write arquillian test cases.
For that I used the following code
#Inject
private ControllerLoginModule controllerloginmodule;
#Deployment
public static WebArchive createDeployment()
{
File[] lib = Maven.resolver()
.resolve("com.controllerjars:controllerbeans:1.0.0","com.controllerjars:controllerapi:2.0.0","com.controllerjars:controllerauth:1.0.0")
.withTransitivity().as(File.class);
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClasses(ControllerLoginModule.class,AuthRealm.class,IAccountManagerInternal.class)
.addAsLibraries(lib)
.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml")
.addAsWebInfResource(new StringAsset("<web-app></web-app>"), "web.xml");
}
#Test
public void testIsDeployed()
{
Assert.assertNotNull(controllerloginmodule);
}
Basically I am loading some jars which contains Classes Under Test and the classes on which those classes depends. In the end I am trying to create a web archive out of it.
Then I try to test that wether object is null or not.
The issue which I can figure out from the stack trace is the deployment is not able to find the files from Maven. Below is the stack trace observed when I try to run the test case.
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive com.appdynamics.auth.ControllerLoginModuleTest.createDeployment()
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:160)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:94)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:57)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:80)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:182)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:156)
... 50 more
Caused by: java.lang.RuntimeException: Could not create new descriptor instance
at org.jboss.shrinkwrap.resolver.api.DependencyBuilderInstantiator.createFromUserView(DependencyBuilderInstantiator.java:101)
at org.jboss.shrinkwrap.resolver.api.DependencyResolvers.use(DependencyResolvers.java:39)
at com.appdynamics.auth.ControllerLoginModuleTest.createDeployment(ControllerLoginModuleTest.java:51)
... 55 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.jboss.shrinkwrap.resolver.api.DependencyBuilderInstantiator.createFromUserView(DependencyBuilderInstantiator.java:96)
... 57 more
Caused by: java.lang.NoSuchMethodError: org.codehaus.plexus.DefaultPlexusContainer.lookup(Ljava/lang/Class;)Ljava/lang/Object;
at org.jboss.shrinkwrap.resolver.impl.maven.MavenRepositorySystem.getRepositorySystem(MavenRepositorySystem.java:220)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenRepositorySystem.<init>(MavenRepositorySystem.java:64)
at org.jboss.shrinkwrap.resolver.impl.maven.MavenBuilderImpl.<init>(MavenBuilderImpl.java:105)
... 62 more
I can't understand where and what I am missing. I have updated the entries for dependencies given in the Can I add jars to maven 2 build classpath without installing them?. Any help is greatly appreciated.
Thanks.
Below is my pom
<?xml version="1.0" encoding="UTF-8"?>
<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">
<!-- Model Information -->
<modelVersion>4.0.0</modelVersion>
<!-- Artifact Information -->
<groupId>com.auth</groupId>
<artifactId>controller.functionaltest</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- Properties -->
<properties>
<version.shrinkwrap.resolver>2.0.0-beta-2</version.shrinkwrap.resolver>
<version.junit>4.11</version.junit>
<version.arquillian_core>1.0.3.Final</version.arquillian_core>
<project.basedir>/controller.functionaltest</project.basedir>
<version.org.jboss.shrinkwrap>1.1.2</version.org.jboss.shrinkwrap>
</properties>
<!-- Dependency Management -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>${version.shrinkwrap.resolver}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.arquillian_core}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Dependencies -->
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${version.arquillian_core}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.controllerjars</groupId>
<artifactId>commonscollections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>com.controllerjars</groupId>
<artifactId>commonutil</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.controllerjars</groupId>
<artifactId>controllerapi</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.controllerjars</groupId>
<artifactId>controllerauth</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.controllerjars</groupId>
<artifactId>controllerbeans</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<type>pom</type>
<version>2.0.0-beta-2</version>
</dependency>
</dependencies>
<!-- Repositories -->
<repositories>
<repository>
<id>JBOSS_NEXUS</id>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</repository>
<repository>
<releases>
<enabled>true</enabled>
<checksumPolicy>ignore</checksumPolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>repo</id>
<url>file://${project.basedir}/src/main/resources</url>
</repository>
</repositories>
<!-- Plugin Configuration -->
<build>
<finalName>controller.functionaltest</finalName>
<!-- Compiler -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<!-- Plugin Management -->
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>[2.1,)</versionRange>
<goals>
<goal>unpack</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>GLASSFISH_REMOTE_3.1_(REST)</id>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<extensions>false</extensions>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-dist</artifactId>
<version>7.1.3.Final</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>~/JBOSS_Managed</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-remote-3.1</artifactId>
<version>1.0.0.CR3</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>JBOSS_AS_MANAGED_7.X</id>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<extensions>false</extensions>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-dist</artifactId>
<version>7.1.3.Final</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>~/JBOSS_Managed</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<version>7.1.3.Final</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
below is my Dependency tree .
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building controller.functionaltest 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) # controller.functionaltest ---
[INFO] com.appdynamics.auth:controller.functionaltest:pom:1.0.0-SNAPSHOT
[INFO] +- org.jboss.spec:jboss-javaee-6.0:pom:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.resource:jboss-connector-api_1.5_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:jar:1.0.0.Final:provided
[INFO] | | \- javax.xml:jaxrpc-api:jar:1.1:provided
[INFO] | +- org.jboss.spec.javax.el:jboss-el-api_2.2_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.security.jacc:jboss-jacc-api_1.4_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.enterprise.deploy:jboss-jad-api_1.2_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.security.auth.message:jboss-jaspi-api_1.0_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.xml.registry:jboss-jaxr-api_1.0_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.jms:jboss-jms-api_1.1_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.servlet.jsp:jboss-jsp-api_2.2_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.xml.bind:jboss-jaxb-api_2.2_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.xml.rpc:jboss-jaxrpc-api_1.1_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.xml.soap:jboss-saaj-api_1.3_spec:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.spec.javax.xml.ws:jboss-jaxws-api_2.2_spec:jar:1.0.0.Final:provided
[INFO] | +- javax.activation:activation:jar:1.1:provided
[INFO] | +- javax.enterprise:cdi-api:jar:1.0-SP4:provided
[INFO] | +- com.sun.faces:jsf-api:jar:2.0.3-b05:provided
[INFO] | +- javax.inject:javax.inject:jar:1:provided
[INFO] | +- javax.jws:jsr181-api:jar:1.0-MR1:provided
[INFO] | +- javax.mail:mail:jar:1.4.2:provided
[INFO] | +- javax.servlet:jstl:jar:1.2:provided
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:provided
[INFO] | +- org.jboss.resteasy:jaxrs-api:jar:2.1.0.GA:provided
[INFO] | +- stax:stax-api:jar:1.0.1:provided
[INFO] | \- javax.validation:validation-api:jar:1.0.0.GA:provided
[INFO] +- junit:junit:jar:4.11:test (scope not updated to runtime)
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.jboss.arquillian.junit:arquillian-junit-container:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.junit:arquillian-junit-core:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.test:arquillian-test-api:jar:1.0.3.Final:test
[INFO] | | \- org.jboss.arquillian.core:arquillian-core-api:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.test:arquillian-test-spi:jar:1.0.3.Final:test
[INFO] | | \- org.jboss.arquillian.core:arquillian-core-spi:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.container:arquillian-container-test-api:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.container:arquillian-container-test-spi:jar:1.0.3.Final:test
[INFO] | | \- org.jboss.arquillian.container:arquillian-container-spi:jar:1.0.3.Final:test
[INFO] | | \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-api-base:jar:2.0.0-alpha-3:test
[INFO] | +- org.jboss.arquillian.core:arquillian-core-impl-base:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.test:arquillian-test-impl-base:jar:1.0.3.Final:test
[INFO] | +- org.jboss.arquillian.container:arquillian-container-impl-base:jar:1.0.3.Final:test
[INFO] | | +- org.jboss.arquillian.config:arquillian-config-api:jar:1.0.3.Final:test
[INFO] | | +- org.jboss.arquillian.config:arquillian-config-impl-base:jar:1.0.3.Final:test
[INFO] | | \- org.jboss.shrinkwrap.descriptors:shrinkwrap-descriptors-spi:jar:2.0.0-alpha-3:test
[INFO] | \- org.jboss.arquillian.container:arquillian-container-test-impl-base:jar:1.0.3.Final:test
[INFO] +- com.controllerjars:commonscollections:jar:3.2.1:compile
[INFO] +- com.controllerjars:commonutil:jar:1.0.0:compile
[INFO] +- com.controllerjars:controllerapi:jar:2.0.0:compile
[INFO] +- com.controllerjars:controllerauth:jar:1.0.0:compile
[INFO] +- com.controllerjars:controllerbeans:jar:1.0.0:compile
[INFO] \- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-depchain:pom:2.0.0-beta-2:compile
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api:jar:2.0.0-beta-2:compile
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-spi:jar:2.0.0-beta-2:compile
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven:jar:2.0.0-beta-2:compile
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven:jar:2.0.0-beta-2:runtime
[INFO] | +- org.sonatype.aether:aether-api:jar:1.13.1:runtime
[INFO] | +- org.sonatype.aether:aether-impl:jar:1.13.1:runtime
[INFO] | +- org.sonatype.aether:aether-spi:jar:1.13.1:runtime
[INFO] | +- org.sonatype.aether:aether-util:jar:1.13.1:runtime
[INFO] | +- org.sonatype.aether:aether-connector-wagon:jar:1.13.1:runtime
[INFO] | +- org.apache.maven:maven-aether-provider:jar:3.0.4:runtime
[INFO] | +- org.apache.maven:maven-model:jar:3.0.4:runtime
[INFO] | +- org.apache.maven:maven-model-builder:jar:3.0.4:runtime
[INFO] | +- org.apache.maven:maven-repository-metadata:jar:3.0.4:runtime
[INFO] | +- org.apache.maven:maven-settings:jar:3.0.4:runtime
[INFO] | +- org.apache.maven:maven-settings-builder:jar:3.0.4:runtime
[INFO] | +- org.codehaus.plexus:plexus-interpolation:jar:1.14:runtime
[INFO] | +- org.codehaus.plexus:plexus-utils:jar:2.0.6:runtime
[INFO] | +- org.apache.maven.wagon:wagon-provider-api:jar:2.2:runtime
[INFO] | +- org.apache.maven.wagon:wagon-file:jar:2.2:runtime
[INFO] | \- org.apache.maven.wagon:wagon-http-lightweight:jar:2.2:runtime
[INFO] | \- org.apache.maven.wagon:wagon-http-shared4:jar:2.2:runtime
[INFO] | +- org.jsoup:jsoup:jar:1.6.1:runtime
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.1.2:runtime
[INFO] | \- commons-io:commons-io:jar:2.0.1:runtime
[INFO] \- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-impl-maven-archive:jar:2.0.0-beta-2:runtime
[INFO] +- org.jboss.shrinkwrap:shrinkwrap-impl-base:jar:1.0.1:runtime
[INFO] | +- org.jboss.shrinkwrap:shrinkwrap-api:jar:1.0.1:runtime
[INFO] | \- org.jboss.shrinkwrap:shrinkwrap-spi:jar:1.0.1:runtime
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-api-maven-archive:jar:2.0.0-beta-2:runtime
[INFO] +- org.jboss.shrinkwrap.resolver:shrinkwrap-resolver-spi-maven-archive:jar:2.0.0-beta-2:runtime
[INFO] +- org.codehaus.plexus:plexus-compiler-javac:jar:2.1:runtime
[INFO] | \- org.codehaus.plexus:plexus-compiler-api:jar:2.1:runtime
[INFO] \- org.codehaus.plexus:plexus-component-api:jar:1.0-alpha-33:runtime
[INFO] \- org.codehaus.plexus:plexus-classworlds:jar:1.2-alpha-10:runtime
I think the cause of this problem is due to ambiguous ShrinkWrap Resolver dependencies. You should declare the ShrinkWrap Resolver Bill of Materials in the dependency Management chain before the Arquillian BOM. I recommend using the ShrinkWrap Resolver 2.0.0-beta-2.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>2.0.0-beta-2</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
<type>pom</type>
</dependency>
</dependencyManagement>
In the dependency section you need to have the following dependencies present:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<type>pom</type>
<version>2.0.0-beta-2</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${arquillian.version}</version>
<scope>test</scope>
</dependency>
The ShrinkWrap Resolver 2.0.0-beta-2 provides a new API for resolving artifacts, so you need to make sure you use that particular API, such as:
File lib = Maven.resolver()
.resolve("artifact-groupid:artifact-artifactid:version")
.withoutTransitivity()
.asSingle(File.class);
return ShrinkWrap.create(WebArchive.class, "test.war")
.addClass(MyClass.class)
.addAsLibrary(lib)
.addAsWebInfResource(new StringAsset("<beans/>"), "beans.xml")
.addAsWebInfResource(new StringAsset("<web-app></web-app>"), "web.xml");
I've created an example project containing the bare minimums needed to make use of ShrinkWrap Resolver which makes use of the configuration and code above, however running in an embedded TomEE container. You can find it here: https://github.com/tommysdk/showcase/tree/master/arquillian-shrinkres. Hopefully this can help you to straight out the correct dependencies and versions needed.
I had the same issue. The reason was that a resource file could not be reached. Example:
.addAsWebResource("index.html")
Index.html file must be in classpath during the test runtime or else the exception that throws is (!):
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.Archive com.intrasoft.ssp.persistence.admin.service.IndexPageTest.createDeployment()
Your POM looks like it is lending to a conflict or missing dependency among the ShrinkWrap artifacts pulled in by Arquillian BOM and the ShrinkWrap Resolvers depchain.
Going by the POM snippet here, I believe you should also add the ShrinkWrap Resolver BOM as a managed dependency, before the Arquillian BOM, in your project POM.