Pass/Fail verification to the output

Sep 10, 2010 at 8:13 AM

I want to know if I have to report the pass/fail verification for the test case, what is the best way to do it? Does the below code contain valid and enough information? Thanks.

 

 

Button button = Window.Get<Button>(SearchCriteria.ByText("Log On"));

Assert.isNotNull(button, "not found")

System.Diagnostics.

Debug.WriteLine("Failed to find button", "Logon"  

button.Click();

// click on the LogOn button

);

 

if (button != null)

                {

                    button.Click();

                }

                else

                {

                    System.Diagnostics.Debug.WriteLine("Failed to click logon button");

                }

 

Sep 10, 2010 at 9:22 AM

what do you want to test?

that the button is there or is the button there and correct?

after Assert fail the test ends so diagnostic part will never be called, the test go in tear down.

String buttoName = "Log On";

Button button = Window.Get<Button>(SearchCriteria.ByText(buttonName));

Assert.isNotNull(button, "can't not found button with name: {0}", buttonName);

Assert.IsTrue(button.Visible, "Button with name {0} should be visible", buttonName);

Assert.IsTrue(button.Enabled, "Button with name {0} should be enabled", buttonName);

button.Click();

// click on the LogOn button

);

This question might be better in a test forum

Throndorin

Sep 10, 2010 at 1:50 PM

Thanks for the explanation. My aim is to verify two things:

1. if the button is there?

2. If so, click on it and print the statmement that it is clicked successfully.

So in any event using WHITE if Asset fail the test stops, is there a way we can continue to move to next step verification even if Asserts fails.? Becuase may be one verification is failed there are other steps we can verify.

 

Sep 10, 2010 at 3:28 PM
Edited Sep 10, 2010 at 3:29 PM

Hi

Continue a test does only make sense if the next steps does not depend on this fail.

 

There might be other ways in Nunit instead of using Asserts, to collect errors but don't stop.

 

We use a class to collect such errors and at the end of the test we call assert.Fail if threre are collected Errors.

 

using System.Collections;
using System.Text;

namespace ETS4TestHelper.Helper
{
  /// <summary>
  /// Special class for handling with errors during the test
  /// </summary>
  public class ErrorLog
  {
    private static ErrorLog _sErrorLog ;
    private static ArrayList _errorList;

    private ErrorLog()
    {
      
    }

    /// <summary>
    /// Gets the instance.
    /// </summary>
    /// <value>The instance.</value>
    public static ErrorLog Instance
    {
      get
      {
        if (_sErrorLog == null)
        {
          _sErrorLog = new ErrorLog();
          _errorList = new ArrayList();
        }
        return _sErrorLog;
      }
    }

    /// <summary>
    /// Adds the error.
    /// </summary>
    /// <param name="error">The error.</param>
    public void AddError(string error)
    {
      _errorList.Add( error );
    }

    /// <summary>
    /// Adds the error.
    /// </summary>
    /// <param name="error">The error.</param>
    /// <param name="args">The args.</param>
    public void AddError(string error, params object[] args )
    {
      _errorList.Add(string.Format(error, args));
    }

    /// <summary>
    /// Gets the count.
    /// </summary>
    /// <value>The count.</value>
    public int Count
    {
      get
      {
        return _errorList.Count;
      }
    }

    
    /// <summary>
    /// Gets the errors.
    /// </summary>
    /// <returns></returns>
    public string GetErrors()
    {
      string result = string.Empty;
      if (_errorList.Count != 0)
      {
        StringBuilder stringBuilder = new StringBuilder( _errorList.Count );
        stringBuilder = stringBuilder.AppendLine();

        for (int i = 0; i < _errorList.Count; i++)
        {
          stringBuilder = stringBuilder.Append( _errorList[i] );
          stringBuilder = stringBuilder.AppendLine();
        }
        result = stringBuilder.ToString();
      }

      return result;
    }

    /// <summary>
    /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    /// </summary>
    public static void Dispose()
    {
      _sErrorLog = null;
      _errorList = null;
    }
  }

}

 

 

 

call

 

 

if(ErrorLog.Instance.Count != null)

{

  Assert.Fail(ErrorLog.Instance.GetErrors());

}

 

 

in TearDown

 

ErrorLog.Dispose();

 

 

Throndorin

Sep 13, 2010 at 1:34 PM

Thank you.