locked
How to improve test coverage for ref arguments using PEX? RRS feed

  • Question

  • Hello,

    Consider the following code:

    public class Converter
    {
        public void Convert(Node from, ref NodeElement to)
        {
            if (from == null)
            {
                to = null;
                return;
            }
            to = to ?? new NodeElement();
            to.Text = from.Text;
    
            to.Children = new NodeElement[from.Children.Count];
            int index = 0;
            foreach (Node fromNode in from.Children)
            {
                NodeElement toNode = null;
                Convert(fromNode, ref toNode);
                to.Children[index] = toNode;
                index++;
            }
        }
    
        public void Convert(NodeElement from, ref Node to)
        {
            if (from == null)
            {
                to = null;
                return;
            }
            to = to ?? new Node();
            to.Text = from.Text;
    
            to.Children.Clear();
      
                foreach (NodeElement fromNode in from.Children)
                {
                    Node toNode = null;
                    Convert(fromNode, ref toNode);
                    to.Children.Add(toNode);
                }
        }
    }
    PEX gives the following warnings when running explorations.
            !warning! [execution] problem with PexExample3.ConverterTest.Convert: parameter type PexExample3.NodeElement& not supported
            !warning! [execution] could not generate any test in 0 runs
          00:00:01.7> Convert01(Converter, NodeElement, Node&)
            !warning! [execution] problem with PexExample3.ConverterTest.Convert01: parameter type PexExample3.Node& not supported
    
    If I change it to out arguments, it works great. This is a simple converter class, but there are classes that convert graphs of 7+ levels deep, so using PEX may help us find bugs we never anticipated,. Those signatures can't be modified.  Is there a technique I can use to improve test coverage with the help of PEX on these classes?

    Thanks in advance.

    Werner

    Wednesday, June 24, 2009 7:27 AM

Answers

All replies