How to create unit test for Page_Load function in ASP.net?
I use the built-in Visual Studio unit test framework. I want to create a unit test that checks Webpage Elements and their values.
I know about selenium and its ability in unit testing.
This is the webpage for checking WebPageControl.ascx.vb:
Public Class WebPageControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TextBox.Visible = False End Sub End Class
This is unit test WebPageControlTest.vb:
Public Class WebPageControlTest Public Sub PageLoadTest() Dim target As WebPageControl_Accessor = New WebPageControl_Accessor() Assert.IsFAlse(target.TextBox.Visible) End Sub End Class
After that, I still get the error message
Test method RechargeTest.WebPageControlTest.PageLoadTest threw exception: System.NullReferenceException: Object reference not set to an instance of an object.
source share