SSISUnit with NUnit

Jun 15, 2009 at 9:14 AM

John,

I've recently being doing some work with BizTalk, and used BizUnit for the unit testing

BizUnit also uses a XML test definition like SSISUnit, so the actual code in each NUnit test is fairly minimal ...

BizUnit.BizUnit bizUnit = new BizUnit.BizUnit(@"..\..\TestCases\SubmissionShouldWriteSuccessToSqlAuditTable.xml");
bizUnit.RunTest();

But it does mean the tests are standard NUnit, so can be run by all the usual suspects ... in my case Resharper    

 

Have you given any thought to running SSISUnit in this way ?

Jun 16, 2009 at 1:37 AM
Edited Jun 16, 2009 at 2:10 AM

I had similar thoughts (have also used BizUnit etc)

My solution was to slightly modify the console test runner to return the "fail count" and exposed the "TestRun" class as public. I uploaded the patch for reference... Add references in unit test project to the console and ssisunit DLLs and.... you can do this:

 

[Test]
public void test()
{
  TestRun testRun = new TestRun();
  int failCount = testRun.RunTest(@"D:\path...\test.ssisUnit", string.Empty, "FAILED");
  Assert.AreEqual(0, failCount);
}

The output goes to Console etc...

See: http://ssisunit.codeplex.com/SourceControl/PatchList.aspx

Jun 16, 2009 at 9:00 AM

Cool ... will download patch and incorporate into my local source tree

Coordinator
Jun 17, 2009 at 12:55 AM

Most of that you can do directly through the API. The ssisUnit.dll assembly has a TestSuite class, that you can call to directly execute a test (that's how I unit test the ssisUnit code itself). That gives you access to the TestStatistics object, which lets you get the Failed and Passed counts. That's also where I'm going to add a collection of the messages, so that they don't have to be trapped thru events.

An item to be aware of (you may have already seen this) - there's an implicit assert for every test that validates whether the task completed successfully. So you have to count an extra assert for that one.

Some sample code for using the API:

 

            SsisTestSuite target = new SsisTestSuite("YourTest.ssisUnit");

            try
            {
                target.Execute();
            }
            catch (Exception ex)
            {

                Assert.Fail(ex.Message);
            }
            //Check to see if test passed
            Assert.AreEqual(1, target.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.TestPassedCount));

            //Check to see if asserts passed
            Assert.AreEqual(2, target.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.AssertPassedCount)); 

            //Check to see if any asserts failed
            Assert.AreEqual(0, target.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.AssertFailedCount)); 

 

 

 

 

 

 

 

 

 

<font size="2">

 

</font>

 

 

Jun 17, 2009 at 3:19 AM

Ah, much nicer!

Just FYI, I am using mstest so I currently have this type of setup:

 

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SsisUnit;

namespace UnitTests
{
    [TestClass]
    public class XYZIntegrationTests : SsisUnitTestBase
    {
        [TestMethod]
        public void Test1()
        {
            ExecuteTestSuite(TestContext.TestName);
        }

        [TestMethod]
        public void Test2()
        {
            ExecuteTestSuite(TestContext.TestName);
        }
    }
    public class SsisUnitTestBase
    {
        protected string _path = @"D:\base-path....\";
        private TestContext _testContext;

        public TestContext TestContext
        {
            get { return _testContext; }
            set { _testContext = value; }
        }

        protected void ExecuteTestSuite(string testSuiteName)
        {
            SsisTestSuite testSuite = new SsisTestSuite(_path + testSuiteName + ".ssisUnit");
            testSuite.Execute();
            Assert.AreEqual(0, testSuite.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.TestFailedCount));
        }
    }
}

 

It's a simple way to run the test files out of the VS test project... 

 

 

Jun 18, 2009 at 9:13 AM

Thanks for the responses John and Paul, off to create a new NUnit test class ...

Jun 4, 2010 at 7:21 AM

Hi -

Can you please suggest how i trigger the test exeution from Visual Studio 08.

Below is how it used to be done with BizUnit.

        [TestMethod]
        public void Test_01_FILECopyWithXmlValidation()
        {
            BizUnit.BizUnit bizUnit = new BizUnit.BizUnit(@"F:\tarun.arora\Visual Studio 2005\Projects\TestSSISUTs\TestProject1\XMLFile1.xml");
            bizUnit.RunTest();
        }

 

Jun 4, 2010 at 9:19 AM

My tests are fairly simple ...

[Test]
public void Support_check_setup_step_sm_send_audit_email()
{
    const string Step = "SM - Send Audit Email";
    int start = Support.CountSmtpMessage();
    Console.WriteLine(string.Format("CountSmtpMessage: {0}", start));

    Support.RunSsisTarget(Step, false);

    Assert.AreEqual(start, Support.CountSmtpMessage());
}

using my wrapper ...  

internal static void RunSsisTarget(string ssisStep, bool ifTrueRunTarget)
{
    SsisTestSuite target = new SsisTestSuite(GetSsisFile(ssisStep));
    if (!ifTrueRunTarget)
    {
        return;
    }

    try
    {
        target.Execute();
    }
    catch (Exception ex)
    {
        Assert.Fail(ex.Message);
    }

    Assert.AreEqual(1, target.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.TestPassedCount));
    Assert.AreEqual(2, target.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.AssertPassedCount));
    Assert.AreEqual(0, target.Statistics.GetStatistic(TestSuiteResults.StatisticEnum.AssertFailedCount));
}

and I've chopped up the original definition file so I have one for each step in my SSIS package ...

<?xml version="1.0" encoding="utf-8"?>
<TestSuite xmlns="http://tempuri.org/SsisUnit.xsd">
  <ConnectionList>
    <Connection name="iTeam_via_OleDb" connection="Provider=SQLNCLI;Server=<your server>;User ID=<your userid>;Password=<your password>;Initial Catalog=iTeam;" connectionType="ConnectionString" />
  </ConnectionList>
  <PackageList>
    <Package name="CTaxLoad" packagePath="E:\Dev\VS2005\SSIS\CTaxPersonIncremental\CTaxPersonIncremental\bin\CTaxLoad.dtsx" storageType="FileSystem" />
  </PackageList>
  <TestSuiteSetup></TestSuiteSetup>
  <Setup></Setup>
  <Tests>
    <Test name="SM - Send Audit Email" package="CTaxLoad" task="{1AF86280-CA31-4D27-A636-99C1A7B6B339}" taskResult="Success">
      <Assert name="Dummy Test" expectedResult="True" testBefore="false" expression="false">
        <DirectoryCommand operation="Exists" argument1="C:\Windows" argument2="Notepad.exe" />
      </Assert>
    </Test>
  </Tests>
  <Teardown></Teardown>
  <TestSuiteTeardown></TestSuiteTeardown>
</TestSuite>
Cheers,

SteveC.