' '************************* ' AutoBuildTest Script ' ' lightweight continious integration solution ' for your desktop projects '******************************** ' ' Author: Zoran Milanovic ' www.anasoft.net ' ' Date: 10/10/2005 ' Revision History: ' Misc: ' 'HOW TO INSTALL: '1-create *.nunit files locations to with test dlls and add the fiel to project root folder '2-add Nunit bin folder location to PATH [ C:\Program Files\NUnit 2.2\bin\?] '3-update project, solution and nunit files path arrays according to projects you want to test '4-optional: enable emailing and set scheduling for ' '''''''''''''''''''''''''''''''''''' ' Enable error handling On Error Resume Next Dim strReport Dim complusappname Dim vs_executable_path Dim nunit_executable_path vs_executable_path="devenv.exe" nunit_executable_path="nunit-console.exe" Dim emalForm Dim emailTo emalForm="youemail@test.com" emalTo="youemail@test.com" Const ForReading = 1, ForWriting = 2, ForAppending = 8 Dim oFSO, oFile, strFilename, strData, strSearch 'add project info here intProjCnt=2 Dim vsprojectArray(2) vsprojectArray (0) = "C:\YourProj1\" vsprojectArray (1) = "C:\YourProj2\" Dim vsprojectSolutionArray(2) vsprojectSolutionArray (0) = "C:\YourProj1\YourProj1.sln" vsprojectSolutionArray (1) = "C:\YourProj1\YourProj2.sln" Dim nunitprojectArray(2) nunitprojectArray(0)="C:\YourProj1\YourTests1.nunit" nunitprojectArray(1)="C:\YourProj1\YourTests1.nunit" Dim shell Set shell = CreateObject("WScript.Shell") 'build projects Dim i Set oFSO = CreateObject("Scripting.FileSystemObject") for i=0 To intProjCnt-1 'delete build output file to avoid appending to file If oFSO.FileExists(vsprojectArray(i) & "projectlastbuild_errors.txt") Then oFSO.DeleteFile vsprojectArray(i) & "projectlastbuild_errors.txt" End If shell.Run vs_executable_path & " /out " & vsprojectArray(i) & "projectlastbuild_errors.txt" & " /rebuild debug " & vsprojectSolutionArray(i) & " ",1,True If Err.number <> 0 Then strReport = strReport & vbCrLf & "ERROR building - " & vsprojectSolutionArray(i) Err.number = 0 End If Next Set oFSO = nothing 'check build result file Set oFSO = CreateObject("Scripting.FileSystemObject") for i=0 To intProjCnt-1 strFileName = vsprojectArray(i) & "projectlastbuild_errors.txt" Set oFile = oFSO.OpenTextFile(strFileName, ForReading) strData = oFile.ReadAll & "something" oFile.Close 'check file for failure message - check for hardcoded message - if fails 7+ project will not detect If (InStr(1,strData,"succeeded, 1 failed") > 0 or InStr(1,strData,"succeeded, 2 failed") > 0 or InStr(1,strData,"succeeded, 3 failed") > 0 or InStr(1,strData,"succeeded, 4 failed") > 0 or InStr(1,strData,"succeeded, 5 failed") > 0 or InStr(1,strData,"succeeded, 6 failed") > 0) Then strReport = strReport & vbCrLf & "FAILED BUILD - " & vsprojectSolutionArray(i) Else strReport = strReport & vbCrLf & "OK BUILD - " & vsprojectSolutionArray(i) End If Next '1 failed 'run all nuints using nunit project for i=0 To intProjCnt-1 shell.Run nunit_executable_path & " " & nunitprojectArray(i) & " /xml:nunit_results.xml /noshadow",1,True If Err.number <> 0 Then strReport = strReport & vbCrLf & "ERROR testing - " & nunitprojectArray(i) Err.number = 0 End If Next 'check xml result file strSearch = "success=" & Chr(34) & "False" & Chr(34) Set oFSO = CreateObject("Scripting.FileSystemObject") for i=0 To intProjCnt-1 strFileName = vsprojectArray(i) & "nunit_results.xml" Set oFile = oFSO.OpenTextFile(strFileName, ForReading) strData = oFile.ReadAll & "something" oFile.Close 'check nunit report file to see if any problem with the test If (InStr(1,strData,strSearch) > 0) Then strReport = strReport & vbCrLf & "FAILED TEST - " & nunitprojectArray(i) Else strReport = strReport & vbCrLf & "PASSED TEST - " & nunitprojectArray(i) End If Next set shell = nothing 'send email is commented out Dim strMessage strMessage= "Rebuilding and Testing on " & CStr(Date) & " " & CStr(Time) & "." & vbCrLf & vbCrLf & "------------------------------------------------" & strReport & vbCrLf & vbCrLf & "Done." 'SendMailOutlook emailTo, "AutoBuildTest Result" , strMessage, emailFrom Wscript.Echo strMessage WScript.Quit 'with Outlook Sub SendMailOutlook(aTo, Subject, TextBody, aFrom) 'Create an Outlook object Dim Outlook 'As New Outlook.Application Set Outlook = CreateObject("Outlook.Application") 'Create e new message Dim Message 'As Outlook.MailItem Set Message = Outlook.CreateItem(olMailItem) With Message 'You can display the message To debug And see state '.Display .Subject = Subject .Body = TextBody 'Set destination email address .Recipients.Add (aTo) 'Set sender address If specified. Const olOriginator = 0 If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator 'Send the message .Send End With End Sub 'with SMTP Sub SendMailSMTP(aTo, Subject, TextBody, aFrom, aAttachFileName ) Set objMessage = CreateObject("CDO.Message") objMessage.Subject = Subject objMessage.From = aFrom objMessage.To = aTo objMessage.TextBody = TextBody objMessage.AddAttachment aAttachFileName objMessage.Send End Sub