0

I'd like to unit test my MS Access application using MS Test in visual studio. This answer: Unit testing vba from .net - strongly typed COM objects along with this MS article: http://support.microsoft.com/kb/306683 has enabled me to get to the point where I can test my own custom functions in an MS Access database:

Imports System.Text
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports Microsoft.Office.Interop

<TestClass()>
Public Class TestDb_Tests

Private oAccess As Access.ApplicationClass

<TestInitialize()>
Public Sub Setup()
    oAccess = New Access.ApplicationClass
    oAccess.Visible = False
    oAccess.OpenCurrentDatabase("C:\Users\anon\Desktop\TestDb.accdb", False)
End Sub
<TestMethod()>
Public Sub CheckSEDOL_ValidSEDOL_ExpectTrue()
    Assert.AreEqual(True, oAccess.Run("CheckSEDOL", "xxxxxxx"))
End Sub
<TestCleanup()>
Public Sub Cleanup()
    oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
    oAccess = Nothing
End Sub
End Class

However I cannot access my own class definitions, to instantiate and then test my own classes (I'd rather not instantiate them in the Access db). The first link above indicates that an interop assembly might help with this, but I cannot use tlbimp.exe to generate one from my MS Access database. I was wondering if this is actually possible and if so would I need to roll my own interop assembly? If so I'd very much appreciate pointers to any resources on how to do this.

Community
  • 1
  • 1
majjam
  • 1,286
  • 2
  • 15
  • 32
  • 1
    But why not just write the test stubs in Access? I fail to see why introduction .net solves any issue here? Your unit tests are simply code stubs that you have to write anyway – why not write such test stubs in VBA unless you can explain what advantages running + calling such code from vb.net has or even solves any issue here? You can certainly call + run any public sub, and that public sub can of course create instances of the VBA class objects, but then again all you get here is some vb.net code calling some VBA code. Why not just write your test stubs in VBA? – Albert D. Kallal Jan 29 '15 at 19:30
  • Thank you, I think I'll go with a hybrid of your answer, creating test stubs in MS Access as required that provide values that can be tested in .net. I'm eager to continue developing the test suite in VS because the long term plan is to migrate the application to .net. – majjam Feb 02 '15 at 11:41

0 Answers0