Download presentation
Presentation is loading. Please wait.
1
Testing servers
2
Testing a server: The idea
Start the server (manually) [TestMethod] Send a request to the server Read the response from the server Compare the response to your expectations Assert.AreEqual(expected, response) Stop the server (manually) Example: EchoTcpServer Note: Although we use a Unit test tool this is not unit testing. It is integration testing
3
Start and stop the server automatically
The test should be able to start and later stop the server automatically The server should have methods Start() and Stop() [ClassInitialize] executed once - before the first [TestMethod] [ClassCleanup] Executed once - after the last [TestMethod] Example: EchoTcpServer
4
Start and stop the server from the test
private const int Port = 14593; private static EchoServer _server; [ClassInitialize] public static void TestStart(TestContext context) { _server = new EchoServer(Port); Task.Run(() => _server.Start()); } [ClassCleanup] public static void TestStop() { _server.Stop(); }
5
The servers Stop() method
Server refuses new connections Existing connections (Tasks) must be given a chance to finish Example: EchoTcpServer
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.