public void TestLayout() { const string title = "Some unit test title!"; // Instantiate the view directly var view = new PrecompiledMvcLibrary.Views.Shared._Layout(); // Set up the data that needs to be access by the view view.ViewBag.Title = title; // Render it as a string var output = view.Render(); // Verify that it looks correct Assert.IsTrue(output.Contains(title)); }