Integration Testing

Integration testing is similar to unit testing in that tests invoke methods of application classes in a unit testing framework. However, integration tests do not use mock objects to substitute implementations for service dependencies. Instead, integration tests rely on the application's services and components. The goal of integration tests is to exercise the functionality of the application in its normal run-time environment.

Integration Testing in the Partner Portal Application

The Partner Portal application includes integration tests. These tests are located in the Test\Microsoft.Practices.SPG.Tests directory. Usually, tests such as these are used as part of a nightly build validation process.

The Partner Portal application includes an integration test solution in Microsoft Visual Studio Team System. This solution includes a Reference Projects folder that contains the functionality to test. The solution has test project that contains individual tests, as shown in the following illustration.

Integration Tests Solution

Ff647876.1ff3a520-68a8-4b33-99dd-be687df93a0c(en-us,PandP.10).png

The test project, Microsoft.Practices.SPG.Tests, is organized by functional area. For example, there are directories named LoggingTest and ServiceLocator.

Logging Integration Tests

The LoggingTest directory includes integration tests that cover both positive and negative cases. Positive tests exercise the expected usage of the class. Negative tests set up conditions that are expected to fail and verify that the code fails as expected.

Each test sets up the conditions for the test, creates an instance of the class under test, performs an operation, and validates the expected result.

The following code shows the test method that verifies the LogToOperations method. This is an example of positive testing.

[TestMethod]
public void LogToOperationsTest()
{

  string strMessage = "Custom Message by Automation Test Code. " +   
                                                      Guid.NewGuid().ToString("N");            

  EventLogEntryType Severity = EventLogEntryType.Error;
  TraceSeverity TSeverity=LogUtils.MapEventLogEntryTypesToTraceLogSeverity(Severity);

  // BaseLogger is abstract so can use the SharePointLogger can be used
  SharePointLogger spLogger = new SharePointLogger(); 
  spLogger.LogToOperations(strMessage, EID_Default, Severity, strDefaultCategory);

  // Validation for Splog Entries
  bool isValidSPL = LogUtils.ValidateSPLogs(strMessage, strDefaultCategory, 
                                                            TSeverity, EID_Default); 

  strMessage = string.Format("Category: {0}\n{1}", strDefaultCategory, strMessage);

  // Validation for event log entry
  bool isValidEL = LogUtils.ValidateEventLog(strEventSourceName, EID_Default, 
                                                             strMessage, Severity); 
  strMessage = null;
  spLogger = null;

  Assert.IsTrue(isValidSPL, "No entry is made in Share point Logs");
  Assert.IsTrue(isValidEL, "No entry is made in Event Logs");

}       

Service Locator Integration Tests

The ServiceLocator test folder includes positive and negative integration tests.

The following code is an example of a negative test from the ActivatingServiceLocatorFactoryTest class. The test validates that an exception is thrown when registering two interfaces.

[ExpectedException(typeof(ArgumentException))]
public void RegisterTypeMapping_K_IType_Test2()
{
   ActivatingServiceLocator ASLocator = new ActivatingServiceLocator();
   ActivatingServiceLocator ASLocator2 =  
        ASLocator.RegisterTypeMapping(typeof(IInterface1), typeof(IInterface2)
                , "Key1", InstantiationType.NewInstanceForEachRequest);

}

Home page on MSDN | Community site

Show: