5
\$\begingroup\$

I have created an extension for unit-testing my own equality implementations. Is it a good approach in general to have such extensions for unit testing? What unit-testing extensions do you use?

public static class EqualityExtensions
 {
 /// <summary>
 /// Checks that all variations Equals method conforms to equality by properties
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="variations"></param>
 /// <param name="propertyAccessors">Property accessors specifying which properties contribute to equality</param>
 /// <returns>True, if all instances from a set conform to property equality</returns>
 /// <example>
 /// Assert.IsTrue(from name in new[] {"foo","bar"} from count in new[] {1,2} select new MyClass{Name=name,Count=count}).ConformToPropertyEquality(x=>x.Name,x=>x.Count))
 /// </example>
 public static bool ConformToPropertyEquality<T>(this IEnumerable<T> variations, params Func<T, object>[] propertyAccessors)
 {
 var propertyComparisions =
 from lhs in variations
 from rhs in variations
 select
 Equals(
 (from comparator in propertyAccessors select Equals(comparator(lhs), comparator(rhs))).All(c => c),
 Equals(lhs, rhs)
 );
 return propertyComparisions.All(p => p);
 }
 }
asked Sep 27, 2011 at 17:36
\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

It's perfectly OK. As an example SharpTestEx is a whole library with such an extensions.

answered Sep 27, 2011 at 19:14
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.