As all big companies, Criteo developers have to provide unit tests to ensure a good code quality.
One month before my annual performance interview, and one week before my Christmas holidays, my manager pointed out to me that most of my C# repositories had a very low coverage:
After half a day of reflection about reflection, I added the following test to all my projects:
[Test]publicvoidTest_All(){ Type entry =typeof(TestConfigRaw);// set a class contained in// the assembly you want to test Assemblyasm= entry.Assembly; foreach(Type type inasm.GetTypes()) { try { foreach(ConstructorInfo ctor in type.GetConstructors()) { try { List<object> args =newList<object>(); foreach(ParameterInfo p in ctor.GetParameters()) { Type pt = p.ParameterType; if(pt.IsValueType) args.Add(Activator.CreateInstance(pt)); else args.Add(null); } object instance =Activator.CreateInstance(type, args.ToArray()); foreach(MethodInfo method in type.GetMethods()) { try { List<object> parameters =newList<object>(); foreach(ParameterInfo p in method.GetParameters()) { Type pt = p.ParameterType; if(pt.IsValueType) parameters.Add(Activator.CreateInstance(pt)); else parameters.Add(null); } method.Invoke(instance, parameters.ToArray()); } catch{} } } catch{} } } catch{} }}
I got a 22% coverage increase:
And many feedbacks :
I’m now dragging all improvement suggestion to fill my backlog for the next Test sprint. If you have some ideas, let me know 🙂
Author: Laurent Vion
-
Our lovely Community Manager / Event Manager is updating you about what's happening at Criteo Labs.
See DevOps Engineer roles