CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Aaron Jensen

March 2008 - Posts

  • Moq's MockBehavior

    Moq has been getting some press lately because it's the newest mock framework on the block. I think it's certainly interesting and I'll have more to say on it later, but I wanted to briefly complain about one aspect real quick.

    Moq touts that it has a more simplified API when compared to something like Rhino.Mocks. The API has a single entry point which certainly aids discoverability, but I question one of the design decisions. I remember seeing someone say that Rhino had too many types of mocks and that that was confusing. Well, I don't think it has this many different Mock Behaviors:

      public enum MockBehavior
      {
        Strict, 
        Normal,
        Relaxed,
        Loose,
        Default = Normal,
      }

    Why have this many? Does anyone know what they do just by looking at them? At least they're documented, but the docs are quite a mouthful:

      public enum MockBehavior
      {
        /// 
        /// Causes the mock to always throw 
        /// an exception for invocations that don't have a 
        /// corresponding expectation.
        /// 
        Strict, 
        /// 
        /// Matches the behavior of classes and interfaces 
        /// in equivalent manual mocks: abstract methods 
        /// need to have an expectation (override), as well 
        /// as all interface members. Other members (virtual 
        /// and non-virtual) can be called freely and will end up 
        /// invoking the implementation on the target type if available.
        /// 
        Normal,
        /// 
        /// Will only throw exceptions for abstract methods and 
        /// interface members which need to return a value and 
        /// don't have a corresponding expectation.
        /// 
        Relaxed,
        /// 
        /// Will never throw exceptions, returning default  
        /// values when necessary (null for reference types 
        /// or zero for value types).
        /// 
        Loose,
        /// 
        /// Default mock behavior, which equals .
        /// 
        Default = Normal,
      }

    I'm of the opinion that you should only have one type of Mock, and that's what Rhino calls Dynamic and Moq calls Loose. I described why here. If I wanted to simplify mocking, I'd start here.

  • The Eleutian Guys join the CodeBetter Guys

    As Dave so promptly pointed out immediately after our grueling hazing that I still have not yet recovered from, Jacob and I have been invited to join CodeBetter. I'm very excited to do so, thanks to everyone at CodeBetter!

    I'm going to cross-post to both our Eleutian Blog and my CodeBetter Blog for now, so don't worry about adjusting your subscriptions unless you start seeing double... and don't want to read my posts twice.

    Thanks again to CodeBetter for having us!

More Posts