greg greg - 2 months ago 19x Question

Testing an HTML Helper

I got my first HTML helper to work, very exciting.
It is working and inserting HTML into a VIEW, so I have managed to learn that much. However, the HTML is not perfect.

I would like to create unit tests to verify the output of the helper.
I have created a new test project , the code for the single test follows

Imports System.Text
Imports System.Web
Imports System.Web.Mvc
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports mvcUtils
Imports mvcUtils.Helpers

<TestClass()> Public Class testBoundField
Inherits baseTestClass

<TestMethod()> Public Sub FormRowHelper_test()

Dim html1 As String = Html.FormRowHelper("controlId")

Assert.AreEqual("perfect html", html1)

End Sub

End Class

The mvcUtils.Helpers is the namespace where we find the helper.
I have dumbed down the HELPER call to focus on the issue. Again, it is working in the MVC project.

There error I am getting is

'FormRowHelper' is not a member of Html

I think I am missing an include. But I am having troubles seeing it.
Any help is appreciated. Thanks.


I think what that is doing inside your test is trying to map to an HTML namespace, not the helper. In your test, you have to construct the HtmlHelper class:

Dim helper As New HtmlHelper([params])

I don't know what it takes to construct the helper class; you may have to mock the instances of the classes it wants (with TypeMock or Moq or something else).