私はSpring Bootアプリを持っており、現在、すべてのテストを個別に、つまり手動で実行すると、すべてのテストが緑色で実行されますが、mavenパッケージコマンドを実行すると、すべてのテストがシリアルモードで実行されます。次に何が起こるかというと、次のようになります。
"java.net.BindException: Address already in use".
基本的に、テストは連続して実行されているため、すべてのテストがソケット 127.0.0.1:8081 を要求しようとします。また、ソケットが TIME_WAIT 状態であるため、2 番目のテストはそのソケットを要求できません。つまり、netstat -apn の出力
netstat -apn |grep -i 8080
tcp 0 0 127.0.0.1:8080 127.0.0.1:33952 TIME_WAIT
これで、開発と運用という 2 つの異なるプロファイルが構成されました。つまり、以下を参照してください。
@Configuration @Profile("Development") public class TomcatEmbededDevelopmentTesting1Profile extends SpringServletContainerInitializer { ... }
@Configuration @Profile("Production") public class TomcatEmbededProductionProfile extends SpringServletContainerInitializer { .. }
私が今探しているのは、どの顧客の TomcatServletContainerInitializer を実行できるかを指定する機能です。つまり、5 つの異なるポート/ソケットをすべてリッスンする必要があります。問題は、すべて「@Profile("Development")」でマークされた 5 つの異なる TomcatEmbeded 構成クラスがある場合、必要なものを実行するように junit に指示する方法です。@SpringApplicationConfiguration の使用にうんざりしていますが、それはうまくいきません。
@SpringApplicationConfiguration(classes = {
...
TomcatEmbededDevelopmentTesting1Profile.class,
...
} )
次に、そのポートをランダム化すると思われる魔法の注釈 @IntegrationTest("server.port:0") があることを説明するネット上の記事を見つけましたが、それもうまくいきませんでした。春に行う正しい方法は何ですか?どんなヒントでも大歓迎です。
ここに私のテストの例があります:
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners(listeners={ ServletTestExecutionListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
WithSecurityContextTestExecutionListener.class
}
)
@SpringApplicationConfiguration(classes = {
SecurityWebApplicationInitializerDevelopment.class,
SecurityConfigDevelopment.class,
TomcatEmbededDevelopmentTesting1Profile.class,
Internationalization.class,
MVCConfigDevelopment.class,
PersistenceConfigDevelopment.class,
ServerAuthenticationSuccessHandler.class,
ServerRedirectAuthenticationSuccessHandler.class,
LogicServiceRegistryPostProcessor.class
} )
@WebAppConfiguration
@EnableWebSecurity
@EnableWebSocket
@EnableGlobalMethodSecurity(prePostEnabled = true)
//@IntegrationTest({"server.port=0", "management.port=0"})
@ActiveProfiles("Development")
public class quickTest extends TestCase {
..
}