Product: Ideas for easing Unit Testing

Specific ideas on how to improve the testability of Sitecore

(thinking…)

Enter your idea and we'll search to see if someone has already suggested it.

If a similar idea already exists, you can support and comment on it.

If it doesn't exist, you can post your idea so others can support it.

Enter your idea and we'll search to see if someone has already suggested it.

  1. Make pipeline arg objects pure POCOs

    Example: HttpRequestArgs has an internal Initialize method. This prevents the ability to instantiate a fully functional args object.

    16 votes
    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)

      We’ll send you updates on this idea

    • Sitecore Configuration Factory should be an abstract class or interface

      As a static factory it's extremely difficult to then return or mock out things like GetDatabase or SiteContext, etc.

      13 votes
      Sign in
      Check!
      (thinking…)
      Reset
      or sign in with
      • facebook
      • google
        Password icon
        I agree to the terms of service
        Signed in as (Sign out)

        We’ll send you updates on this idea

      • Make SiteContext mockable

        SiteContext construction currently depends on a SiteInfo, which creates dependencies on logging and caches... so dependent on Sitecore config.

        11 votes
        Sign in
        Check!
        (thinking…)
        Reset
        or sign in with
        • facebook
        • google
          Password icon
          I agree to the terms of service
          Signed in as (Sign out)

          We’ll send you updates on this idea

        • Create Documentation on ways to test or isolate sitecore components

          A lot of this, and learning how to instantiate and create testable sitecore components, could be helped along by better documentation on how to mock or create sitecore components instead of poking around with ILSpy

          6 votes
          Sign in
          Check!
          (thinking…)
          Reset
          or sign in with
          • facebook
          • google
            Password icon
            I agree to the terms of service
            Signed in as (Sign out)

            We’ll send you updates on this idea

            1 comment  ·  Admin →
          • Make all item fields abstract or "pure virtual" to support recursive mocks in NSubstitute

            Sitecore 8.2 makes creating NSubstitute items very useful, as all methods are virtual. However, because types like ItemPath and Field have non-virtual methods or have non-default construstors, it is not possible to use NSubstitute's recursive mock feature to do things like:

            subItem.Paths.FullPath.Returns("/sitecore/content/home");
            subItem.Fields["Some Field"].Value.Returns("some value");

            instead, it is necessary to do things like:
            subItem.Paths.Returns(Substitute.For<ItemPath>());
            subItem.Fields["Some Field"].Returns(Substitute.For<Field>(ID.NewID, subItem);

            By replacing these field types with abstract base classes, the friction of using Substitutes would be greatly reduced.

            See http://nsubstitute.github.io/help/auto-and-recursive-mocks/
            ("A pure virtual class is defined as one with all its public methods and properties defined as virtual or abstract and with a…

            6 votes
            Sign in
            Check!
            (thinking…)
            Reset
            or sign in with
            • facebook
            • google
              Password icon
              I agree to the terms of service
              Signed in as (Sign out)

              We’ll send you updates on this idea

            • Make IQueryable Sitecore Search objects unit testable

              Sitecore search code is incredibly difficult if not impossible to unit test as I understand it right now. It in my opinion is also one of the most important areas in a Sitecore implementation.

              If it is actually testable, publicise it, if not - the ability to test a generated IQueryable would be just awesome.

              This might be as simple as a .ToString() that returns "Where the property {0} equals {1}" with appropriate values assigned. This in turn would generate a string that we as developers could assert.

              4 votes
              Sign in
              Check!
              (thinking…)
              Reset
              or sign in with
              • facebook
              • google
                Password icon
                I agree to the terms of service
                Signed in as (Sign out)

                We’ll send you updates on this idea

              • Create wrapper and interface for WebUtil

                All of the Util classes could use this, but I would start with WebUtil since it is probably the most widely used. It would be better in the long run to refactor the utility classes to adhere to the single responsibility principle, but adding wrappers and interfaces would be a lot easier.

                1 vote
                Sign in
                Check!
                (thinking…)
                Reset
                or sign in with
                • facebook
                • google
                  Password icon
                  I agree to the terms of service
                  Signed in as (Sign out)

                  We’ll send you updates on this idea

                • Don't see your idea?

                Product: Ideas for easing Unit Testing

                Feedback and Knowledge Base