Visual studio tests and client server programs

I have a solution that is a client server. Client and server are projects in one solution.

I want a unit test client, which obviously requires the server to work. Is there a way to indicate in the unit test project that the server project should be started before a specific unit test is started? I suppose I could explicitly run the program, but I would prefer the testing framework to do this for me.

I assume this is a fairly common requirement. How do people usually approach him? (VS2010, C # if that matters.)

+3
source share
6 answers

- REAL . , , .

unit test , . , , -, , ..

unit test "Mocking" , . .

+3

: , - . , :)

, -, ( , ); ( ). "" - .

, , .

+4

, , , . , , .

TestRun start/stop

MSTest AssemblyInitializeAttribute. , .

[TestClass]
public class AssemblyTestHarness
{
    [AssemblyInitialize]
    public static void InitializeAssembly(TestContext context)
    {
        // start process here
    }

    [AssemblyCleanup]
    public static void CleanupAssembly(TestContext context)
    {
        // clean-up process here
    }
}

/ Test Fixture

, .

[TestClass]
public class MyTestFixture
{
    [ClassInitialize]
    public static void InitializeFixture(TestContext context)
    {
        // start process here
    }

    [ClassCleanup]
    public static void CleanupFixture(TestContext context)
    {
        // clean-up process here
    }
}
+2

, . , , ( , ).

- , ​​ MoQ RhinoMock. , , , , .

+1

no. This is not unit testing. You should not test the client on the server through unit tests. To do this, you need to run Mock what the server returns in its unit tests. This is the "unit test" way of your client server code.

+1
source

you just have to shut down the server using an isolation environment like Moq / RhinoMock or whatever you prefer. unit test should not depend on starting / running anything: perhaps you will test a client with a real server component on your Integration Test.

0
source

All Articles