Так что я недавно начал сталкиваться с TestNGException
, пытаясь запустить наш существующий набор тестов с помощью среды IDE. В последнее время я имею в виду обновление intelliJ и зависимостей, чтобы попробовать работать с последними версиями. Код и стек трассировки для отказа заключается в следующем -org.testng.TestNGException при попытке доступа к PoolingHttpClientConnectionManager
Код Использование
ITests.java -
public class ITests extends BaseTest {
private final Action action = new Action();
}
BaseTest (только АКЦИЮ синтаксис) -
public class BaseTest {
// where in this class does not use any instance of Http
}
Action.java -
public class Action {
private final Http http = Http.getInstance();
}
Http.java -
public class Http {
private static final Http INSTANCE = new Http(); //line 36
public static Http getInstance() {
return INSTANCE;
}
private Http() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); //line 43
connectionManager.setMaxTotal(100);
connectionManager.setDefaultMaxPerRoute(100);
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(60000)
.setConnectTimeout(60000)
.setConnectionRequestTimeout(60000)
.build();
this.client = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig)
.setConnectionManager(connectionManager).build();
}
}
Maven зависимостей -
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
StackTrace -
org.testng.TestNGException: Cannot instantiate class com.package.tests.test.ITests at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:40) at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:382) at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:295) at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:118) at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:183) at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:128) at org.testng.TestRunner.initMethods(TestRunner.java:416) at org.testng.TestRunner.init(TestRunner.java:242) at org.testng.TestRunner.init(TestRunner.java:212) at org.testng.TestRunner.<init>(TestRunner.java:159) at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:549) at org.testng.SuiteRunner.init(SuiteRunner.java:161) at org.testng.SuiteRunner.<init>(SuiteRunner.java:114) at org.testng.TestNG.createSuiteRunner(TestNG.java:1290) at org.testng.TestNG.createSuiteRunners(TestNG.java:1277) at org.testng.TestNG.runSuitesLocally(TestNG.java:1131) at org.testng.TestNG.run(TestNG.java:1048) at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72) at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:122) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:29) ... 18 more Caused by: java.lang.NoSuchMethodError: org.apache.http.impl.conn.CPool.setValidateAfterInactivity(I)V at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:176) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:158) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:125) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:116) at com.package.core.Http.<init>(Http.java:43) at com.package.core.Http.<clinit>(Http.java:36) at com.package.tests.action.Action.<init>(Action.java:16) at com.package.tests.test.ITests.<init>(ITests.java:24) ... 23 more
Примечание - Наш проект является базой на мавена, поэтому пока я выполнить тесты с использованием maven exec:java
выполнение идет отлично.
Просьба указать любую другую информацию.
Edit 1 -
Как спросил @hunter, отладка, чтобы получить точный путь Cpool
, откуда он загружен. Оценивается -
Class.forName("org.apache.http.impl.conn.CPool").getResource("CPool.class")
Результат -
файл: /Users/xyz/.m2/repository/org/apache/httpcomponents/httpclient/4.5.2/httpclient-4.5.2.jar/орг/Apache/HTTP/осущ/подкл/CPool.Класс
Edit 2 -
mvn dependency:tree
[наиболее тесно связанные с httpcomponents] -
--- Maven-зависимость-плагин: 2,8: дерево
com.package: core: jar: 1.1.3
+- org.apache.httpcomponents:httpclient:jar:4.5.2:compile | +- org.apache.httpcomponents:httpcore:jar:4.4.4:compile | +- commons-logging:commons-logging:jar:1.2:compile | \- commons-codec:commons-codec:jar:1.9:compile
+- com.google.collections:google-collections:jar:1.0:compile
+- commons-io:commons-io:jar:2.5:compile
+- org.apache.commons:commons-lang3:jar:3.4:compile
+- org.json:json:jar:20160810:compile \- org.testng:testng:jar:6.9.9:compile
com.package: Тест: баночка: 1.1.3
+- mysql:mysql-connector-java:jar:6.0.3:compile
+- org.apache.httpcomponents:httpclient:jar:4.5.2:compile | +- org.apache.httpcomponents:httpcore:jar:4.4.4:compile | +- commons-logging:commons-logging:jar:1.2:compile | \- commons-codec:commons-codec:jar:1.9:compile
+- com.package:mobile:jar:3.6.2:compile | +- com.pkg.serviceproxy:http-handler:jar:1.7.41:compile | | +- org.apache.httpcomponents:httpcore-nio:jar:4.3:compile | +- com.pkg:bullseye-model:jar:1.2.0:compile | | +- com.codahale.metrics:metrics-httpclient:jar:3.0.2:compile | +- kpg:pz-api:jar:0.2.38:compile | | \- com.mashape.unirest:unirest-java:jar:1.4.7:compile | | +- org.apache.httpcomponents:httpasyncclient:jar:4.0.2:compile | | \- org.apache.httpcomponents:httpmime:jar:4.3.6:compile
+- com.package:core:jar:1.1.3:compile
com.package: водитель: баночка: 1.1.3
\- com.package:test:jar:1.1.3:compile
Редактировать 3 - IntelliJ IDEA - 15.0.3 [Community] - обновление 19 января, 2016
Edit 4 -
Гибка больше к intelliJ, совместное использование журналов после запуска тестов с использованием testng.xml -> right click -> run
> objc[21590]: Class JavaLaunchHelper is implemented in both
> /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java
> and
> /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib.
> One of the two will be used. Which one is undefined.
> [[email protected]] error can't determine annotations of missing
> type javax.cache.annotation.CachePut when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes
> when weaving [Xlint:cantFindType] [[email protected]] error
> can't determine annotations of missing type
> javax.cache.annotation.CacheResult when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes
> when weaving [Xlint:cantFindType] [[email protected]] error
> can't determine annotations of missing type
> javax.cache.annotation.CacheRemove when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes
> when weaving [Xlint:cantFindType] [[email protected]] error
> can't determine annotations of missing type
> javax.cache.annotation.CacheRemoveAll when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes
> when weaving [Xlint:cantFindType]
отладить тест и поместить первый конструктор Http-конвейера точки прерывания, а при ударе точки останова это выражение Class.forName ("org.apache.http.impl.conn.CPool"). GetResource ("CPool.class") – hunter
@hunter - это то, что мы пытаемся достичь с этим (прочитайте - какая информация указана?) – nullpointer
отобразит, где загружен класс Cpool, обычно это должно быть из вашего локального репозитория maven . но мы можем проверить, что время исполнения прогноза погоды относится к правильной банке. он должен показать путь, PLS обновить сообщение с этим результатом – hunter