简体   繁体   中英

How to test Server-Client (Java/Maven)

I have a simple game which consists of two projects: Client and server. Now I want to test if they interact correctly.
Setup is: One Maven-parent project, and server/client as child-modules.

I don't now how to test the interaction: am I able to start both project somehow (how exactly?) in junit tests, or integration tests? So that I can listen for one projects output verify it and send it to the other? Or should I go another way?

For integeation tests create a seperate pom add both projects as test dependencies. Then start the server using testng beforeclass hooks or the maven failsafe plugin hook before the test starts, and close the server after the test.

通常,您从测试启动服务器,然后从测试发送请求,以模拟客户端行为并检查服务器响应是否符合您的期望。

This sounds like a good case for an integration test. I would do it as follows:

  • create a third maven module called IntegrationTests
  • use a maven profile integrationtests and activate it with -Dintegrationtests
  • pull in the client and server modules as dependencies in the new module
  • write my integration tests using JUnit (@Before, @Test, etc)

As Evgeniy suggested, you could of course put the integration tests in one of the existing modules, whereas my suggestion is to split it out to a third module.

If you need help on how to use maven profiles for integration testing, just google around, or feel free to ask if you have specific questions.

Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM