Too many tests on simple viewing?

Hi, I am building my website, and although it is very simple, I decided to check as many aspects of it as possible. Using ethics only to write useful tests that could take into account situations that I could imagine (renaming a script or css file, etc.)

I am using the Steve Sanderson MVC integration testing platform and my tests below.

My question is twofold, this is the level of testing "too much", and if not, then what other scenarios (as a developer, for example, renaming, and something else) you might think.

using System.Web; using System.Web.Mvc; using MvcIntegrationTestFramework.Hosting; using NUnit.Framework; using website.Properties; namespace website.tests { [TestFixture] public class HomeControllerIndexTests { [TestFixtureSetUp] public void Setup() { appHost = AppHost.Simulate("Website"); } [Test] public void HomeControllerIndexReturnsTheIndexView() { appHost.Start(session => { var result = session.Get("/Home/Index"); Assert.AreEqual("Index", ((ViewResult)result.ActionExecutedContext.Result).ViewName); }); } [Test] public void HomeControllerIndexReturnsCorrectRouteData() { appHost.Start(session => { var result = session.Get("/Home/Index"); Assert.AreEqual("Home", result.ActionExecutedContext.RouteData.Values["controller"]); }); } [Test] public void HomeControllerIndexReturnsViewResult() { appHost.Start(session => { var result = session.Get("/Home/Index"); Assert.IsInstanceOf(typeof(ViewResult), result.ActionExecutedContext.Result); }); } [Test] public void HomeControllerIndexReturnsNoError() { appHost.Start(session => { var result = session.Get("/Home/Index"); Assert.IsNull(result.ResultExecutedContext.Exception); }); } [Test] public void HomeControllerIndexReturnsViewWithSiteCssFile() { appHost.Start(session => { var result = session.Get("/Home/Index"); Assert.IsTrue(result.ResponseText.Contains("/Content/Site.css")); }); } [Test] public void HomeControllerIndexReturnsViewWithCorrectTitle() { appHost.Start(session => { var result = session.Get("/Home/Index"); Assert.IsTrue(result.ResponseText.ToLowerInvariant().Contains("<title>{ me: danielelliott.info(); }</title>")); }); } [Test] public void HomeControllerIndexReturnsViewContainingBanner() { appHost.Start(session => { var result = session.Get("/Home/Index"); var expected = HttpUtility.HtmlEncode(Resources.SiteName); Assert.IsTrue(result.ResponseText.Contains(expected)); }); } [Test] public void HomeControllerIndexViewIncludesBioParagraph() { appHost.Start(session => { var result = session.Get("/Home/Index"); var expected = HttpUtility.HtmlEncode(Resources.Bio.ToLowerInvariant()); Assert.IsTrue(result.ResponseText.ToLowerInvariant().Contains(expected)); }); } [Test] public void HomeControllerIndexViewIncludesServicesParagraph() { appHost.Start(session => { var result = session.Get("/Home/Index"); var expected = HttpUtility.HtmlEncode(Resources.Services.ToLowerInvariant()); Assert.IsTrue(result.ResponseText.ToLowerInvariant().Contains(expected)); }); } [Test] public void HomeControllerIndexViewIncludesHistoryParagraph() { appHost.Start(session => { var result = session.Get("/Home/Index"); var expected = HttpUtility.HtmlEncode(Resources.History.ToLowerInvariant()); Assert.IsTrue(result.ResponseText.ToLowerInvariant().Contains(expected)); }); } private AppHost appHost; } } 
+7
source share
2 answers

Testing always depends on the context, and the risks you see should determine the scope of testing.

  • How important would it be if some part would not work after some changes?
  • Do you think these parts can break down when something has changed?
  • How important would it be to support these tests if the page structure changed?
  • Do you think these parts change frequently? Is it paid to automate them?
  • How long will the test take to increase the amount? Are you ready to wait a long time to see that the latest changes have not broken anything?

If the page does not change very often, this amount seems rather large. You might also wonder if this is enough to check just a sample of things. For example, it seems that you include several parts of the page. If they come from the same place and are included in the same mechanism, it seems unlikely that the inclusion of one of them will fail if the others are.

On the other hand, it is always easier to reduce the amount. You can start with this while learning, and then see if you need to change your approach later.

+1
source

My reaction when I see your tests is that they basically check implementation details. I would recommend you focus on behavior. Check end-user interaction with the site. Make sure the information is present, not how it is presented.

+1
source

All Articles