statlight does not call TestInitialize

Jan 7, 2011 at 5:05 PM

I use statlight to run unit tests created with Silverlight Unit Test framework and the TestInitialize cod of my test class does not get executed.

The test creates a control which is added to the root panel like below; in the test method, the view control object is always null.

The cmd line is statlight -x="unittests.xap" -o=MsTest -r="reports/results.xml"; any idea why the initialization does not happen?

 

Thanks,

Vasile.

 

  

[TestClass]
    public class CommonResourceViewTests : OpsConsoleSilverlightTest
    {
        CommonResourceView view;

        [TestInitialize]    
        public void TestSetup()    
        {        
			view = new CommonResourceView();
			view.ResourceType = GlobalConstants.SummaryType.RunBook;

			// add the view to the test panel
			this.TestPanel.Children.Add( view );
        }

        }

       

[TestMethod]
        public void CommonResourceView_View() 
        {
			if ( view != null )
			{

 

Coordinator
Jan 8, 2011 at 12:42 AM

[TestInitialize] is recognized in StatLight. The following test will prove that...

 

[TestClass]
public class Tests
{
    private int _setupValue;

    [TestInitialize]
    public void Setup()
    {
        _setupValue = 1234;
    }
    [TestMethod]
    public void TestMethod1()
    {
        Assert.AreEqual(1234, _setupValue);
    }
}

Unfortunately the Microsoft Silverlight testing framework does not report exceptions up in the setup methods that have the [TestInitialize] attribute in a way that we can figure out what's going on.

I will sometimes call the setup explicitly in a seperate "test" and call it SmokeTest - until I get my setup code right.

[TestClass]
public class Tests
{
    private int _setupValue;

    [TestInitialize]
    public void Setup()
    {
        throw new NotImplementedException("Test");
    }


    [TestMethod]
    public void SmokeTest()
    {
        Setup();
    }

    [TestMethod]
    public void TestMethod1()
    {
        Assert.AreEqual(1234, _setupValue);
    }
}

Hope this helps.

Mar 11, 2011 at 2:00 PM

Hello, It looks like if the TestInitializeAttribute-decorated methods are executed by starlight, the same cannot be said about AssemblyInitializeAttribute.

Can someone confirm that, and if there is one : expose a workaround to overcome this limitation ?

Note : We used to have code run in TestInitialize-decorated methods to AssemblyInitialize-decorated methods : the tests run fine locally within visual studio, which uses Resharper + AgUnit, but we have hundreds of tests failing on our Continuous Integration server which uses Statlight to run the tests.

Regards,

 

Fabio

Coordinator
Mar 11, 2011 at 4:21 PM

salfab - would you please create a work item and describe all the Assembly related attributes you use and what you think should be supported? I agree, and think this could possibly get into the next release of StatLight. Just want to understand what all you need in there...

Thanks,
Jason 

Coordinator
Mar 13, 2011 at 6:35 PM

I dug into this a bit - the code looked like it should be supported, but turns out there was a bug causing it to not work. I'll have this fixed by the next release. If you need it sooner, monitor the github commits and build the latest when you see the commit pushed up there.

Mar 18, 2011 at 9:01 AM

Hello staxmanade,

Thanks for the quick response.

I just pulled the latest sources from github and compiled statlight.exe and statlight.core.dll and replaced the ones from the distrib 1.3 with the new builds.

Unfortunately, when I run statlight, I get a messagebox with the following message :

 

( pardon my french, or rather, the french of os where statlight is installed ;) 

Message de la page web means 'web page message'
la valeur ne peut pas être means : "the value cannot be", and
Nom du paramètre means 'parameter name')

 

---------------------------
Message de la page Web
---------------------------
Unhandled Error in Silverlight Application
Super Secret StatLight Code: 836D4425-DB59-48BB-BA7B-03AB20A57499
Code: 4004   
Category: ManagedRuntimeError      
Message: System.ArgumentNullException: La valeur ne peut pas être null.

Nom du paramètre : uriString

   à System.Uri..ctor(String uriString)

   à StatLight.Client.Harness.Hosts.NormalStatLightSystem.OnTestRunConfigurationDownloaded(ClientTestRunConfiguration clientTestRunConfiguration)

   à StatLight.Client.Harness.Hosts.StatLightSystemBase.<GoGetTheTestRunConfiguration>b__11(Object sender, OpenReadCompletedEventArgs e)

   à System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)

   à System.Net.WebClient.OpenReadOperationCompleted(Object arg)    

---------------------------
OK  
---------------------------

Mar 18, 2011 at 9:01 AM

p.s. I love the "Super Secret StatLight Code" ;)

Mar 18, 2011 at 9:04 AM

Update :

After closing the messagebox and waiting a few minutes, the console added  the following notifications :

C:\Phoenix\trunk\Polyright.PersonManager\PersonManager>3rdParty\BuildTools\StatLight\StatLight.exe -x="Polyright.PersonManager.Server.Web\ClientBin\Polyright.PersonManager.Client.Shell.Test.xap"

StatLight - Version 1.3.4094
Copyright (C) 2009 Jason Jarrett
All Rights Reserved.

 

Starting Test Run: 18.03.2011 09:57:31


No communication from the web browser has been detected. We've waited longer than the configured time of 00:05:00

------------------ Test Failed ------------------
Test Namespace:
Test Class:
Test Method:
Other Info: No communication from the web browser has been detected. We've waited longer than the configured time of 00:05:00
-------------------------------------------------


--- Completed Test Run at: 18.03.2011 10:02:34. Total Run Time: 00:05:03.2500000

Test run results: Total 1, Successful 0, Failed 1,

Coordinator
Mar 18, 2011 at 12:39 PM

Based on what's you've posted I have two things for you to try.

1. Run statlight with the -b parameter (This will force the UI to show run)

If that works, great, that means you have UI related tests. (I have not put anything together to detect this scenario and warn you to use the -b option (yet))

2. If the above doesn't work, then please run your original command again with the --debug parameter and post the results, that might help me see what's possibly getting hung up?

Mar 21, 2011 at 1:39 PM

here are some update :

I've run your tests and here are the outcome :

1. the same behavior occurs, only this time, before getting the messagebox, a white window opens very briefly, showing the famous "blue balls" indicating a silverlight app is loading, then nothing, the window is back to white. ( the Unit Tests runner doesn't show up )

2. At some point, before getting the messagebox, the log produces the following output :

    add -  WriteableBitmapEx.dll
        updateed AppManifest - WriteableBitmapEx
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton
COULD NOT FIND THE okButton

If you want me to send you the complete debug file, please give me your email address so I can send it to you in private.

Apr 18, 2011 at 7:15 AM

Hello staxmanade,

I would like to know the status of the support of AssemblyInitializeAttribute in StatLight.

We have hundred of Silverlight tests that fail in TeamCity because it seems the AssemblyInitialize attribute is not supported.

I read the previous posts, but there is no follow-up.

Thanks.

Coordinator
Apr 18, 2011 at 12:44 PM

Hello labate,

The AssemblyInitialize should be working and is in the latest source. You can download the latest at github and run one of the release build .bat files to get a build that should work for you.

Hope this helps.

Apr 18, 2011 at 5:31 PM

staxmanade,

Thank you for your answer.

I followed your advice and all went well. I build a version 1.4.4125 that makes pass all the tests that failed before.

Thanks.

Coordinator
Apr 18, 2011 at 7:18 PM

labate,

Great to hear.

Please don't hesitate to post any new issue you see with your build. I'd like to wrap up an official release relatively soon, so addressing issues is at the of my priority...

Thanks