Freigeben über


How To Generate Unit Test Using WCF Load Test – Quick Steps

 Alik Levin    This is quick summary of steps for creating WCF Unit Tests using WCF Load Test available for free on Codeplex. This quick summary created based on the Lab materials that ship with the tool.

Quick Resource Box

Summary of steps

  • Step 1. Configure message tracing in the app.config file on client side.
  • Step 2. Run WCF client to invoke the remote methods and generate trace file.
  • Step 3. Generate Unit test based on trace file.

Step 1. Configure message tracing in the app.config file on client side.

  1. Select the Diagnostics folder.
  2. Under Message Logging click Enable Message Logging.
  3. Click Log Level and check Service messages. The other options can be unchecked.
  4. Click ServiceModelMessageLoggingListener and change the file name to be “WCFClient.svclog”.
  5. Under the Message Logging folder enable LogEntireMessage.
  6. Save the configuration file.

Step 2. Run WCF client to invoke the remote methods and generate trace file.

Run your WCF client. Make sure WCFClient.svclog generated. This log file will be used in the next step to generate Unit Tests

Step 3. Generate Unit test based on trace file.

  • Create a new test project in Visual Studio.
  • Add a reference to the following assemblies:
    • System.ServiceModel
    • System.Runtime.Serialization (version 3.0.0.0)
  • In the directory containing the test project create a file called SampleConfig.xml with the following contents: 
 <?xml version='1.0' encoding='utf-8' ?><WcfUnitConfiguration xmlns='https://microsoft.com/wcfunit'                           testMethodMode='ScenarioMethodOnly'                           operationTimerMode='IncludeOperationTimers'>       <assembly fileName="C:\Client\bin\Debug\ConsoleClient.exe"/>     <soapActions soapActionMode='Include'>     </soapActions></WcfUnitConfiguration>
  • Open an SDK command prompt and change the directory to the one containing the test project.
  • Execute the following command: svcutil /o:proxy.cs /config:app.config https://localhost:8090/service?wsdl
  • Run the command-line tool using the following command: “c:\program files\wcfunit\wcfunit” CompileTimeScenario <trace file> SampleConfig.xml where the <trace file> is the path to the WCFClient.svclog file created in the previous exercise.
  • Add generated files (CompileTimeScenario.cs and CompileTimeScenario.stubs) to the test project.
  • Rename CompileTimeScenario.stubs to CompileTimeScenario.Stubs.cs.
  • Also add the proxy.cs and app.config files located in the client project folder to the test project.
  • Build the solution and a Unit Test called CompileTimeScenario should appear in the Test View.

Comments

  • Anonymous
    August 18, 2009
    regardingstep 1:where can i find app.config file?step2:where can i find WCF client?
  • Anonymous
    August 23, 2009
    suneetha,I suggest you following the explanations detailed here:http://wcfloadtest.codeplex.com/