2016-11-05 2 views
0

Мы пытаемся выполнить интеграционный тест с использованием testng, и springboot.app работает нормально, и мы можем запускать автономный тест с использованием eclipse.but, когда мы запускаем тестовый файл с помощью команды maven command.i я получать следующее исключениеОшибка при запуске интеграционного теста с весенней загрузкой и testng

org.apache.coyote.AbstractProtocol start 
SEVERE: Failed to start end point associated with ProtocolHandler ["http-nio-8080"] 
java.net.BindException: Address already in use: bind 
     at sun.nio.ch.Net.bind0(Native Method) 
     at sun.nio.ch.Net.bind(Net.java:433) 
     at sun.nio.ch.Net.bind(Net.java:425) 

если попытаться загрузить context.xml для запуска TestCase то каждый TestCase пытается загрузить свой собственный контекст и TestCase не удается с хост не найден исключение.

базовый класс TestCase

//@ContextConfiguration(locations={"classpath:objectModelContext.xml"}) 
@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 
public class BaseITCase extends com.test.common.BaseITCase { 

    protected static final String baseUrl = "http://localhost:" + port + "/test/api/"; 

    protected String getAdminToken(String username, String password, String deviceId) throws Exception { 
    } 
} 

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>om.test</groupId> 
<artifactId>springboot</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>jar</packaging> 
<name>springboot</name> 
<url>http://maven.apache.org</url> 
<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.4.1.RELEASE</version> 
</parent> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <start-class>com.test.App</start-class> 
    <tomcat.version>7.0.65</tomcat.version> 
</properties> 
<dependencies> 
    <dependency> 
     <groupId>org.reflections</groupId> 
     <artifactId>reflections-maven</artifactId> 
     <version>0.9.9-RC2</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-velocity</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>ch.qos.logback</groupId> 
       <artifactId>logback-classic</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>slf4j-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.postgresql</groupId> 
     <artifactId>postgresql</artifactId> 
     <version>9.4-1200-jdbc41</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-data-jpa</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>ch.qos.logback</groupId> 
       <artifactId>logback-classic</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <!-- only dependency needed --> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-jersey</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>ch.qos.logback</groupId> 
       <artifactId>logback-classic</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>slf4j-api</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>com.googlecode.plist</groupId> 
     <artifactId>dd-plist</artifactId> 
     <version>1.8</version> 
     <!-- corresponds to r108 --> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpmime</artifactId> 
     <type>jar</type> 
     <scope>test</scope> 
    </dependency> 
    <!-- Test --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-test</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.8.13</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.assertj</groupId> 
     <artifactId>assertj-core</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.shiro</groupId> 
     <artifactId>shiro-web</artifactId> 
     <version>1.2.4</version> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.2</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-maven-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>pre-integration-test</id> 
        <goals> 
         <goal>start</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>post-integration-test</id> 
        <goals> 
         <goal>stop</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <maxAttempts>600</maxAttempts> 
       <fork>true</fork> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-failsafe-plugin</artifactId> 
      <version>2.19.1</version> 
      <!--$NO-MVN-MAN-VER$--> 
      <executions> 
       <execution> 
        <id>integration-tests</id> 
        <phase>integration-test</phase> 
        <goals> 
         <goal>integration-test</goal> 
         <goal>verify</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

Update

Тесты выполняются с использованием mvn clean install

Я пытаюсь искать пример, но я не нахожу никакого решения.

+0

Все ли тесты ИТ расширяют BaseITCase? –

+0

Да все тестовые расширения baseit – Vish

+0

Весенняя загрузка пытается запустить тесты на порту 8080, даже если вы укажете 'SpringBootTest.WebEnvironment.RANDOM_PORT'. Как вы запускаете тест с maven? –

ответ

0

выглядит правильная конфигурация и сервер запущенный proplerly на порт 8008.my приложении не выбирали правильный порт во время выполнения тестовых случаев, давая соединение отказалось ошибка

следующих изменения были сделаны в basetest случая, поскольку SpringRunner не требуются с testng

@ContextConfiguration(locations={"classpath:objectModelContext.xml"}) 
//@RunWith(SpringRunner.class) 
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 
public class BaseITCase extends com.test.common.BaseITCase { 

    protected static final String baseUrl = "http://localhost:" + port + "/test/api/"; 

    protected String getAdminToken(String username, String password, String deviceId) throws Exception { 
    } 
} 
+0

Итак, он работает сейчас? –

+0

Да .. спасибо за то, что дали мне направление – Vish

Смежные вопросы