0

With a custom control (lets call it TwoLists) that contains two asp:DropDownList (defined in .ascx), I create an instance of TwoLists in my unit test, to find its child lists are nothing.

Public Sub test_TwoLists()
    Dim instance As TwoLists = New TwoLists()
    Dim list1 As DropDownList = instance.FindControl("list1")
    Dim list2 As DropDownList = instance.FindControl("list2")
    Assert.IsNotNull(list1)
    Assert.IsNotNull(list2)
End Sub

Why is the control not initialized with it's child controls?

Note: This control is created/intialised and works fine when being used in an .aspx and I navigate to the page.

Jono
  • 3,949
  • 4
  • 28
  • 48
  • 2
    Pretty sure the lists don't get added til Init...and your test doesn't seem to be simulating life-cycle events or anything. – cHao Oct 15 '12 at 23:52
  • Okay, I really need to read up on the life-cycle. Do you know of any way to simulate the life-cycle events? – Jono Oct 16 '12 at 04:02
  • Highly related: [ASP.NET - How do you Unit Test WebControls?](http://stackoverflow.com/q/31151/319403) – cHao Oct 16 '12 at 05:38
  • Which is to say, no...i don't know a foolproof way. I imagine user controls are a pain to test, period. What i'm finding online seems to agree. But a tool made for testing stuff like that (if it exists) would pretty much have to trigger the control's events somehow. Probably by extending the Page class and adding the control to it. – cHao Oct 16 '12 at 05:44

0 Answers0