Distributed Unit Testing 
by Pablo Santos and Francisco J. Garcia


Example 1:
public interface IPNUnitServices
{
   void NotifyResult(string TestName,PNUnitTestResult result);
   void InitBarrier(string TestName, string barrier);  
   void InitBarrier(string TestName, string barrier, int Max);  
   void EnterBarrier(string barrier);
}


Listing One

public class Barrier
{
    private int mCount;
    private int mMaxCount;
    private Object mLock = new Object();
    public Barrier(int maxCount)
    {
        mCount = 0;
        mMaxCount = maxCount;
    }
    public void Enter()
    {
        lock( mLock )
        {
            ++mCount;
            if( mCount >= mMaxCount )
            {                    
                mCount = 0;
                Monitor.PulseAll(mLock);
            }
            else
                Monitor.Wait(mLock);
        }
    }
    public void Abandon()
    {
        lock( mLock )
        {
            --mMaxCount;
            if( mCount >= mMaxCount )
            {                    
                mCount = 0;
                Monitor.PulseAll(mLock);
            }
            
        }
    }
}


Listing Two

using System;

using NUnit.Framework;
using PNUnit.Framework;

namespace SimpleTest
{    
    [TestFixture]
    public class Test
    {
        [Test]
        public void FirstTest()
        {
            string[] testParams = 
                PNUnitServices.Get().GetTestParams();
            PNUnitServices.Get().InitBarrier("BARRIER");
            // wait two seconds
            System.Threading.Thread.Sleep(2000);
            PNUnitServices.Get().WriteLine(
                string.Format(
                    "FirstTest started with param {0}",
                    testParams[0]));
            PNUnitServices.Get().EnterBarrier("BARRIER");                
        }
        public void SecondTest()
        {   
            PNUnitServices.Get().WriteLine(
                "Second test will wait for first");
            PNUnitServices.Get().InitBarrier("BARRIER");                
            // will wait for the first test
            PNUnitServices.Get().EnterBarrier("BARRIER");
            PNUnitServices.Get().WriteLine(
                "First test should be started now");
        }
        
    }
}
               
Lisitng Three

<TestGroup>
    <ParallelTests>
        <ParallelTest>
            <Name>SimpleTest</Name>
            <Tests>
                <TestConf>
                    <Name>FirstTest</Name>
                    <Assembly>test00.dll</Assembly>
                   <TestToRun>SimpleTest.Test.FirstTest</TestToRun>
                    <Machine>localhost:8080</Machine>
                    <TestParams>
                        <string>Option1</string> 
                    </TestParams>                                                                                
                </TestConf>
                <TestConf>
                    <Name>SecondTest</Name>
                    <Assembly>test00.dll</Assembly>
                    <TestToRun>SimpleTest.Test.SecondTest</TestToRun> 
                    <Machine>testbox:8080</Machine>
               </TestConf>         
          </Tests>
      </ParallelTest>
   </ParallelTests>
</TestGroup>








1


