You can write a test method anywhere, you just need to use the 3A rule (Arrange, Act, Assert) and decorate your methods based on the testing structure used. You can test almost everything using the testing framework, properties, methods, etc.
However, it is best practice to create a separate test project.
Also, Page_Load , like other page lifecycle methods, is not a good option for testing, because it will be cumbersome to test it. I agree with "oleksii" that functionality is something we can test outside of the Page_Load method.
source share