locked
How do I pass a test in TestInitialize? RRS feed

  • Question

  • During TestInitialize I check some pre conditions and if they are false I use
    Assert.Inconclusive

    However I would like pass the test but there is no Assert.Pass()

    How would I go about doing this from TestInitialize?

    Thanks

    Colin

    Tuesday, December 21, 2010 10:54 PM

All replies

  • Hi,

    You can use

    Assert.IsTrue(true);

    Thanks,

    Anuj

    • Proposed as answer by Mike Paterson Wednesday, December 22, 2010 12:28 AM
    Tuesday, December 21, 2010 11:15 PM
  • No this does not work. The code simply skips over to the next statement. I need to pass the test and exit so that it shows up as passed in the test results.

    Thanks

    Colin

     

    Saturday, January 1, 2011 8:07 PM
  • Hi,

    Can you please explain your scenario. Why do you want to simply pass the test even if its failing. The test will always pass if there isnt any exception or an assert failure.

    If your test is failure beacuse of an assert failure then its a genuine failure and you wouldnt want it to pass. I case you want to make it pass, remove the assert statement.

    And if you test is failing because of an exception, use the try catch block to cath the exception.

    Thanks,

    Anuj

    Saturday, January 1, 2011 8:53 PM
  • I have a set of generic tests that excercise different SQL commands in different data providers. Based on a configuration file the tests use a different provider, however some providers don't support every part of the SQL language. For example I have a test that tests FULL OUTER JOIN, now Microsoft Access doesn't support FULL OUTER JOINS so I want that test to pass without running (Ideally I would like to ignore tests on a testrunconfig by testrunconfig basis, but that functionality is not available). However other providers support FULL OUTER JOINS so in that case I want to run the test. At the moment I use

    [TestInitialize]
    public void TestInitialize()
    {
    	if (_ignoredTests.Contains(_testContext.TestName))
    	{
    		Assert.Inconclusive("Test: {0} is not supported for datasource: {1}.", _testContext.TestName, _datasourceType.ToString());
    	}
    }
    

    Where _ignoredTests is loaded with all the unsupported tests for that provider. If I could swap Assert.Inconclusive for Assert.Pass that would be ideal.

    Colin

    Saturday, January 1, 2011 8:59 PM
  • Hi,

    Instead of doing thi in TestInitailize, you could do the following in your test method

    [TestMehod]
    public void MyTest()
    {
    	if (!_ignoredTests.Contains(_testContext.TestName))
    	{
    		//Write your test code here...
    	}
    }
    

    This would make your test case to pass for unsupporte scenario.

    Another approach would be that you could also create two separate test list in your test list editor, one for supported scenario and other for unsupported. Two test lists can contain the same test too, so it shouldnt be a problem. 

    Thanks,

    Anuj

    Saturday, January 1, 2011 9:49 PM
  • I don't want to write this code into every test. I want to write it once in the [TestInitialize] method which works for the Assert.Inconclusive approach.

    I'll have a look at the lists option.

    Thanks

    Colin

    Monday, January 3, 2011 12:37 AM
  • Just use empty test method.

    Have fun with Reporting Service


    Wednesday, December 12, 2012 12:12 PM