About Links Archives Search Feed Albums of Note

Are bug fix tests unit or integration?

Jeremy Miller asked how do you know if your TDD approach is working [http://codebetter.com/blogs/jeremy.miller/archive/2007/10/01/from-a-tdd-fanboy-s-viewpoint-how-you-know-your-approach-to-tdd-or-just-plain-unit-testing-is-working.aspx] earlier today. And then I wrote the following test which covers a particular bug  feature of xsd.exe [/post/2006/05/26/XmlSerialiser-again-dotNet-v11-to-v2-migration-woes-part-4aspx.aspx] I found a while ago. It’s incomplete, but then I started worrying, is this approach right? I’m testing one method which takes a schema and returns a CodeNamespace which has been altered. I need to make sure the result addresses the bug that was discovered which this test seems to do. But is it a unit test? Shouldn’t it have fewer asserts as I’ve read in the past? Shouldn’t I be satisfied with the tests I’ve also written on routines that perform the tweaking on the CodeNamespace once it has been generated, but which do not make sure that all those smaller routines work together to produce the overall result? What are your thoughts out there.

[Test] public void Convert_ComplexTypeHasElementInChoiceWithNoType _GeneratedCodeFixesTypeOfObjectBug() { XmlSchema schema = sb.CreateSchemaContaining(new XmlSchemaObject[] { sb.RootElementWithSeparateType(rootElementName, rootTypeName), sb.NamedComplexTypeContaining(rootTypeName, sb.ChoiceOf(sb.DateStringAndEmptyElements( dateElementName, stringElementName, emptyElementName))) }); //Convert it CodeNamespace ns = sc.ConvertSchemaToCodeNamespace(schema);

//Check that the empty class has been generated CodeDomAssert.AssertClassExists(ns, emptyElementName + “Class”);

//Find the original class and check it has a choice element in it //which isn’t typeof(object) but which is typeof(emptyElementClass)

foreach (CodeTypeDeclaration typeDec in ns.Types) { if (typeDec.Name == rootTypeName) { //Check that the choice element is fielded by a property of type //system object tagged with //[XmlElement(“emptyElement”, typeof(emptyElementClass))]

    <span class="rem">//Create attributes to check</span>         CustomAttribute emptyElementAttribute = <span class="kwrd">new</span> CustomAttribute(         CustomAttributeType.Simple, elementAttributeName,         <span class="kwrd">new</span> AttributeArgument[] {            <span class="kwrd">new</span> AttributeArgument(               CustomArgumentType.Simple, String.Empty, emptyElementName),            <span class="kwrd">new</span> AttributeArgument(               CustomArgumentType.TypeOf, String.Empty,                    emptyElementName + <span class="str">&quot;Class&quot;</span>)         });

    CodeDomAssert.AssertFieldExists(            typeDec.Members, MemberAttributes.Private, <span class="str">&quot;System.Object&quot;</span>,         HelperFunctions.DefaultXsdGeneratedFieldName(defaultGeneratedPropertyName));

    CodeDomAssert.AssertTaggedPropertyExists(            typeDec.Members, defaultGeneratedPropertyName, <span class="str">&quot;System.Object&quot;</span>,            <span class="kwrd">true</span>, <span class="kwrd">true</span>,             HelperFunctions.DefaultXsdGeneratedFieldName(defaultGeneratedPropertyName),            <span class="kwrd">new</span> CustomAttribute[] { emptyElementAttribute });     } }


Posted on October 2, 2007   #Geek Stuff  

← Next post    ·    Previous post →