Exemple #1
0
        // Make special string to be displayed on an Android display
        private static void FormatException(TestError e, List <string> lines, bool isInnerException)
        {
            lines.Add(e.Exception.GetType().Name + ":");
            // We don't add the message here as it has already been written above the stack trace.

            int index = 0;
            IEnumerable <StackFrame> frames;

            if (isInnerException)
            {
                StackTrace st = new StackTrace(e.Exception, true);
                frames = st.GetFrames();
            }
            else
            {
                frames = FilterStackTrace(e.Exception);
            }

            foreach (StackFrame sf in frames)
            {
                MethodBase method       = sf.GetMethod();
                bool       isTestMethod = (method.GetCustomAttributes(typeof(TestMethodAttribute), true).Length != 0);
                lines.Add(string.Format("  at {0}.{1}({2})", method.DeclaringType.Name, method.Name,
                                        (method.GetParameters().Length == 0 ? "" : "..."))
                          );
                if (sf.GetFileName() != null)
                {
                    // line numbers and file names are available (only when debugger is attached)
                    string filename = sf.GetFileName();
                    filename = filename.Substring(filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1);
                    lines.Add(string.Format("    in {0}:{1}", filename, sf.GetFileLineNumber()));
                }

                index++;
            }

            if (e.Exception.InnerException != null)
            {
                lines.Add("");
                lines.Add("------- inner exception ---------");
                lines.Add("");
                FormatException(new TestError(e.Exception.InnerException), lines, true);
            }
        }
Exemple #2
0
 /// <summary>
 /// Manually set the outcome of this method. If you use <see cref="Run"/>, you don't need to call this method.
 /// </summary>
 /// <param name="outcomeError">the exception resulted from calling the method. <c>null</c> if the method didn't
 /// throw an exception.</param>
 public void SetOutcome(Exception outcomeError)
 {
     if (outcomeError == null)
     {
         this.OutcomeError = null;
         this.State        = TestState.Passed;
     }
     else
     {
         if (outcomeError is AssertInconclusiveException)
         {
             this.State = TestState.Inconclusive;
         }
         else
         {
             this.State = TestState.Failed;
         }
         this.OutcomeError = new TestError(outcomeError);
     }
 }
Exemple #3
0
        private static string CreateExceptionString(TestError e, TextView tv)
        {
            List <string> lines = new List <string>();

            FormatException(e, lines, false);
            int maxChar = FindCharacterLineCount(tv);

            StringBuilder sb = new StringBuilder(512);

            foreach (string line in lines)
            {
                if (line == "")
                {
                    sb.AppendLine();
                }
                else
                {
                    sb.Append(WordWrap(line, maxChar));
                }
            }

            return(sb.ToString());
        }
Exemple #4
0
 /// <summary>
 /// Usually this method shouldn't be invoked directly. Use <see cref="TestClass.Reset"/> instead.
 /// </summary>
 public virtual void Reset()
 {
     this.State        = TestState.NotYetRun;
     this.OutcomeError = null;
 }
        // Make special string to be displayed on an Android display
        private static void FormatException(TestError e, List<string> lines, bool isInnerException)
        {
            lines.Add(e.Exception.GetType().Name + ":");
              // We don't add the message here as it has already been written above the stack trace.

              int index = 0;
              IEnumerable<StackFrame> frames;
              if (isInnerException) {
            StackTrace st = new StackTrace(e.Exception, true);
            frames = st.GetFrames();
              }
              else {
            frames = FilterStackTrace(e.Exception);
              }

              foreach (StackFrame sf in frames) {
            MethodBase method = sf.GetMethod();
            bool isTestMethod = (method.GetCustomAttributes(typeof(TestMethodAttribute), true).Length != 0);
            lines.Add(string.Format("  at {0}.{1}({2})", method.DeclaringType.Name, method.Name,
                                                     (method.GetParameters().Length == 0 ? "" : "..."))
                 );
            if (sf.GetFileName() != null) {
              // line numbers and file names are available (only when debugger is attached)
              string filename = sf.GetFileName();
              filename = filename.Substring(filename.LastIndexOfAny(new char[] { '\\', '/' }) + 1);
              lines.Add(string.Format("    in {0}:{1}", filename, sf.GetFileLineNumber()));
            }

            index++;
              }

              if (e.Exception.InnerException != null) {
            lines.Add("");
            lines.Add("------- inner exception ---------");
            lines.Add("");
            FormatException(new TestError(e.Exception.InnerException), lines, true);
              }
        }
        private static string CreateExceptionString(TestError e, TextView tv)
        {
            List<string> lines = new List<string>();
              FormatException(e, lines, false);
              int maxChar = FindCharacterLineCount(tv);

              StringBuilder sb = new StringBuilder(512);

              foreach (string line in lines) {
            if (line == "") {
              sb.AppendLine();
            }
            else {
              sb.Append(WordWrap(line, maxChar));
            }
              }

              return sb.ToString();
        }