Common method for outputting arrays and lists of any type

In unit tests I might want to output the results of a returned list of any type. Instead of writing a new method for each type, here are some techniques with thanks to:

Using Join

Split is a useful function, here is the reverse Join

int[] actual = new int[] {1,2,3}

string actual = new string[] {“one”, “two”, “three”}

TestContext.WriteLine(string.Join(“, “, actual));


Using Generics

public void PrintCollection<T>(IEnumerable<T> col)
foreach (var item in col) TestContext.WriteLine(item);


Using ForEach(Action a)

publicvoid AListTest()
List<string> target = newList<string>();

privatevoid PrintCollection2(string s)




Database Unit Test


Cool – Easy – Very Useful



Test Project Root Namespace disabling referenced project namespace

Had a project SRS.Business.EntityModel
and so created TestProject.SRS.Business.

I found that this project could not code against the first. However when I subtly changed the Test Project Root Namespace in this case to TestProject.SRSBusiness it worked.

How to use “external” configuration files e.g. SharedApp.config with a test project?

Test method TestProjectBusiness.dsBusinessHelperTest.FillAdviceNoteTest threw exception:
System.Configuration.ConfigurationErrorsException: Unable to open configSource file ‘SharedApp.config’. (…Visual Studio 2010\Projects\…\TestResults\…\Out\TestProject.DLL.config line 8)

Solution at:

“If you edit the test run configuration (by double clicking the .testrunconfig file that gets put into the ‘Solution Items’ solution folder when you add a new unit test), you get a test run configuration dialog. There’s a section there called ‘Deployment’ where you can specifiy files or whole folders from anywhere in the solution that can be copied out with the compiled assemblies at run time to the correct folder.

In this way, I can now actually just define most of my configuration in one set of external .config files and have them automatically copied out at the run of each test.”

My Notes:
This works. You may have to close and re-open the test run – test list editor .vsmdi for the appropriate test-settings to take affect.

‘Assembly.Namespace(s).ClassName.Private Sub MethodName’ is not accessible in this context because it is ‘Private’

 If when coding a new test you get the following error:

‘Assembly.Namespace(s).ClassName.Private Sub MethodName’ is not accessible in this context because it is ‘Private’

  • Go to Method Name for which you wish to create test
  • Create a private accessor
  • Go to test method you are creating
  • Change the type of the object you are creating to ..ClassName_Accessor
  • You should now be OK. May need to change some to ..ClassName_Accessory and not others

Good when you know how

Data-Driven Unit Tests

See Book Wrox Professional Application Lifecycle Management p121
VS > Test > Windows > Test View > Select Test > Properties
Data Connection String .. Elipse or type “Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True”
Data Table Name: Name of Schema.Table or View with data list

Alternatively in code:
    Public Property TestContext() As TestContext

    <TestMethod(), DataSource(“System.Data.SqlClient”, “Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True”, “SchemaName.TableOrViewName”, DataAccessMethod.Sequential)> _
    Public Sub SQLViewTest()
TestContext.DataRow(ColumnName or Index).ToString

Team City – Continuous Integration and Automated Testing

If Team City returns "Failure" > "Build Errors"
error MSB4019: The imported project "C:\Microsoft.VisualBasic.targets" was not found.
Then Team City is not using Microsoft Framework 3.5
Then go to Project Settings > Runner >
If using Visual Studio 2008 for a project .proj file then use
Build Version 3.5
Tools Version 3.5

Sln2008 only for solution files

Move to Server
Download – install – choose port
Access from another computer by using server address : port no.

Using Microsoft SQL Server
In order to use Windows Authentication need to copy dll file. In my case was
…Microsoft SQL Server JDBC Driver\sqljdbc_2.0\enu\auth\x86\sqljdbc_auth.dll
into Windows\System32 directory
file was

How do I find a text in SQL Object ?

Started with:
Adapted to:

ALTER PROCEDURE [Testing].[uspFindText]


nvarchar(50) = ‘EFI’
, @TextToFind nvarchar(100)
–, @Type int = 0 –0 = ALL, 1 = PROCEDURE



@SQL nvarchar(500)
+ @TextToFind + ‘%”’