Modify source to skip tests and add a reason

Mar 15, 2013 at 1:41 PM
Edited Mar 15, 2013 at 1:42 PM
Hi,

We found this plugin very usfeull and we want to add some custom logic to it.

We have downloaded the source code of AgUnit 0.7 and we want to skip some tests. We are doing so by editting SilverlightUnitTestTaskRunner.ExecuteSilverlightTasks() as:
(...)
private void ExecuteSilverlightTasks(TaskExecutionNode node)
{
    var assemblyTaskProviders = UnitTestTaskProviderFactory.GetAssemblyTaskProviders();
    var classTaskProviders = UnitTestTaskProviderFactory.GetClassTaskProviders();
    var methodTaskProviders = UnitTestTaskProviderFactory.GetMethodTaskProviders();

    var taskEnvironment = new TaskEnvironment(Server, assemblyTaskProviders, classTaskProviders, methodTaskProviders);
    var taskNode = new TaskNode(node, taskEnvironment);

    foreach (var silverlightTaskNode in taskNode.GetSilverlightTasks())
    {
        silverlightTaskNode.Execute(SkipIfNecessary);
    }
}

/// <summary>
/// Skips the silverlight unit test.
/// </summary>
/// <param name="silverlightTask">The silverlight task.</param>
private static void SkipIfNecessary(SilverlightTask silverlightTask)
{
    var message = string.Format("Skiping {0}...", silverlightTask.Node.Task.Id);
    var logger = new TraceLogger(LogChatterLevels.Full);
    logger.Information(message);
}
This is very basic, so we would like to specify that those tests are being ignored for a reason.

Is it any way to do so?

Thanks
Coordinator
Mar 15, 2013 at 5:50 PM
Edited Mar 15, 2013 at 5:51 PM
Yes, you can use:

silverlightTask.Node.NotifyFinished("Some reason here", TaskResult.Skipped);

This will also fix the status of the items above the test (the test class / namespace / assembly).

What's the reason you're not just using the [Ignore] attribute on the tests ?
Mar 27, 2013 at 3:24 PM
Edited Mar 27, 2013 at 4:28 PM
Thanks for the reply,

Unfortunately I can't get it working, this is the code I am using:
public class SilverlightUnitTestTaskRunner : RecursiveRemoteTaskRunner
{
[...]
        private void ExecuteSilverlightTasks(TaskExecutionNode node)
        {
            var assemblyTaskProviders = UnitTestTaskProviderFactory.GetAssemblyTaskProviders();
            var classTaskProviders = UnitTestTaskProviderFactory.GetClassTaskProviders();
            var methodTaskProviders = UnitTestTaskProviderFactory.GetMethodTaskProviders();

            var taskEnvironment = new TaskEnvironment(Server, assemblyTaskProviders, classTaskProviders, methodTaskProviders);
            var taskNode = new TaskNode(node, taskEnvironment);

            foreach (var silverlightTask in taskNode.GetSilverlightTasks())
            {
                silverlightTask.Node.NotifyStarting();
                silverlightTask.Node.NotifyFinished("This is a reason.", TaskResult.Skipped);
            }
        }
}
That's how I am doing it:
  • Buidl the plugin
  • Close VS
  • Copy the files to it's folder in resharper's installation folder
  • Start VS
  • Check for the plugin to be correctly installed.
  • Open my solution.
  • Run one Silverlight unit test.
It says always "Ignored" with no reason.

This is my machine setup:
  • .NET Framework 4.0.303019
  • Silverlight 5.1.10411.0
  • Visual Studio 2010
  • AgUnit 0.7 source code builded in VS2010.
What am I doing wrong?
Coordinator
Mar 27, 2013 at 5:59 PM
Edited Mar 27, 2013 at 11:07 PM
In your example you're only doing NotifyFinished() on the root task nodes (your solution).
They are recursive: each node has child nodes (projects, namespaces, testclasses, tests, ...).

I'll post a more detailed example later.
Mar 28, 2013 at 8:12 AM
Edited Mar 28, 2013 at 8:30 AM
Aha, thanks for that info, I'll wait for that example :)

Meanwhile I am debugging it and it seems that some libraries are not found.

From the resharper.log:
[ExternalSourcesProjectFilesManager] Execute Changes  *A(NAMESPACE1)
[Caches] <CacheManager> AssemblyChanges: 1
[PMM] Modify: NAMESPACE12, Version=1.0.0.0, Culture=neutral, PublicKeyToken=485c7b508f2591d7
[PMM] change begin
[PMM] change end
[ExternalSourcesProjectFilesManager] Execute Changes  *A(NAMESPACE2)
[Caches] <CacheManager> AssemblyChanges: 1
Can't resolve reference NAMESPACE3, Version=1.5.2.0, Culture=neutral, PublicKeyToken=ebb7bb93ac082f1e from PATH/TO/LIBRARY.dll
SessionStateChanged
Then starts all this lines:
VSDocumentOperationsHandler::ConnectToStream, id 41397582 text stream:37033924
And these are the final lines:
TaskRunner output end
OnSessionStateChanged
OnSessionStateChanged
SessionStateChanged
Counters not valid
SessionStateChanged
ExecSessionChange
SessionStateChanged
PreviewUpdate
SilverlightUnitTestTaskRunner is not reached while debugging and the SL unit test is ignored. Can this resolving exceptions be the problem?

Edit: If I execute againt he same test after a while, that is the output:
09:28:08.921: Thread:1: OnSessionContentsChanged
09:28:08.936: Thread:1: OnSessionStateChanged
09:28:08.936: Thread:1: OnSessionStateChanged
09:28:08.936: Thread:1: OnSessionStateChanged
09:28:16.019: Thread:1: SessionStateChanged
09:28:16.019: Thread:5: TaskRunner output:
09:28:16.034: Thread:1: SessionStateChanged
09:28:16.050: Thread:1: SessionStateChanged
09:28:16.362: Thread:1: PreviewUpdate
09:29:00.384: Thread:5: 
09:29:00.384: Thread:5: TaskRunner output end
09:29:00.384: Thread:5: OnSessionStateChanged
09:29:00.384: Thread:5: OnSessionStateChanged
09:29:00.385: Thread:1: SessionStateChanged
09:29:00.385: Thread:1: Counters not valid
09:29:00.396: Thread:1: SessionStateChanged
09:29:00.552: Thread:1: ExecSessionChange
09:29:00.552: Thread:1: SessionStateChanged
09:29:00.858: Thread:1: PreviewUpdate