Skip to content

Commit

Permalink
Introducing Test Category
Browse files Browse the repository at this point in the history
  • Loading branch information
rkapka committed Jul 20, 2018
1 parent ab68630 commit 65b96df
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 4 deletions.
48 changes: 48 additions & 0 deletions Rubberduck.Core/UI/UnitTesting/TestExplorerControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@

</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

<CollectionViewSource x:Key="ResultsByCategory" Source="{Binding Model.Tests}">
<CollectionViewSource.SortDescriptions>
<componentModel:SortDescription PropertyName="Category" />
<componentModel:SortDescription PropertyName="Declaration.QualifiedName.MemberName" />
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>

<PropertyGroupDescription PropertyName="Category" />

</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

<SolidColorBrush x:Key="ToolBarToggleButtonVerticalBackground" Color="#FFEEF5FD"/>
<SolidColorBrush x:Key="ToolBarButtonHover" Color="#210080FF"/>
<SolidColorBrush x:Key="ToolBarGripper" Color="#FF6D6D6D"/>
Expand Down Expand Up @@ -504,6 +517,11 @@
<Image Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask--arrow.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding RunSelectedCategoryTestsCommand}" Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer ,Key=TestExplorer_RunSelectedCategoryTests}" >
<MenuItem.Icon>
<Image Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask--arrow.png" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding RunInconclusiveTestsCommand}" Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_RunInconclusiveTests}" >
<MenuItem.Icon>
<Image Source="pack://application:,,,/Rubberduck.Resources;component/Icons/Fugue/flask--exclamation.png" />
Expand Down Expand Up @@ -572,6 +590,15 @@
Command="{Binding SetLocationGroupingCommand}"
CommandParameter="{Binding ElementName=GroupByLocation, Path=IsChecked}"
controls:MenuItemGroup.GroupName="TestExplorer_GroupingStyle" />
<MenuItem x:Name="GroupByCategory"
Style="{DynamicResource MenuItemStyle}"
VerticalAlignment="Center"
Header="{Resx ResxName=Rubberduck.Resources.RubberduckUI, Key=GroupingStyle_ByCategory}"
IsChecked="{Binding GroupByCategory, UpdateSourceTrigger=PropertyChanged}"
IsCheckable="True"
Command="{Binding SetCategoryGroupingCommand}"
CommandParameter="{Binding ElementName=GroupByCategory, Path=IsChecked}"
controls:MenuItemGroup.GroupName="TestExplorer_GroupingStyle" />
</MenuItem>
</Menu>

Expand Down Expand Up @@ -615,6 +642,7 @@
</DataGridTemplateColumn>
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_QualifiedModuleName}" Binding="{Binding Declaration.QualifiedName.QualifiedModuleName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_MethodName}" Binding="{Binding Declaration.IdentifierName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_CategoryName}" Binding="{Binding Category}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Message}" Binding="{Binding Result.Output}" Width="*" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
</DataGrid.Columns>
Expand All @@ -633,6 +661,26 @@
</DataGridTemplateColumn>
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_QualifiedModuleName}" Binding="{Binding Declaration.QualifiedName.QualifiedModuleName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_MethodName}" Binding="{Binding Declaration.QualifiedName.MemberName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_CategoryName}" Binding="{Binding Category}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Message}" Binding="{Binding Result.Output}" Width="*" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
</DataGrid.Columns>
</controls:GroupingGrid>
<controls:GroupingGrid ItemsSource="{Binding Source={StaticResource ResultsByCategory}}"
SelectedItem="{Binding SelectedTest}"
ShowGroupingItemCount="True"
Visibility="{Binding IsChecked, ElementName=GroupByCategory, Converter={StaticResource BoolToVisibility}}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Outcome}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate DataType="unitTesting:TestMethod">
<Image Source="{Binding Result.Outcome, Converter={StaticResource OutcomeIconConverter}}" Height="16" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_QualifiedModuleName}" Binding="{Binding Declaration.QualifiedName.QualifiedModuleName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_MethodName}" Binding="{Binding Declaration.QualifiedName.MemberName}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_CategoryName}" Binding="{Binding Category}" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Message}" Binding="{Binding Result.Output}" Width="*" />
<DataGridTextColumn Header="{Resx ResxName=Rubberduck.Resources.UnitTesting.TestExplorer, Key=TestExplorer_Duration}" Binding="{Binding Result.Duration, StringFormat={}{0}ms}" />
</DataGrid.Columns>
Expand Down
77 changes: 73 additions & 4 deletions Rubberduck.Core/UI/UnitTesting/TestExplorerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,43 @@ public class TestExplorerViewModel : ViewModelBase, INavigateSelection, IDisposa
RunFailedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunFailedTestsCommand, CanExecuteRunFailedTestsCommand);
RunPassedTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunPassedTestsCommand, CanExecuteRunPassedTestsCommand);
RunSelectedTestCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteSelectedTestCommand, CanExecuteSelectedTestCommand);
RunSelectedCategoryTestsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteRunSelectedCategoryTestsCommand, CanExecuteRunSelectedCategoryTestsCommand);

CopyResultsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), ExecuteCopyResultsCommand);

OpenTestSettingsCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), OpenSettings);

SetOutcomeGroupingCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
{
GroupByOutcome = (bool)param;
GroupByLocation = !(bool)param;
GroupByOutcome = true;
if ((bool)param)
{
GroupByLocation = false;
GroupByCategory = false;
}
});

SetLocationGroupingCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
{
GroupByLocation = (bool)param;
GroupByOutcome = !(bool)param;
GroupByLocation = true;
if ((bool) param)
{
GroupByOutcome = false;
GroupByCategory = false;
}
});

SetCategoryGroupingCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), param =>
{
GroupByCategory = true;
if ((bool)param)
{
GroupByOutcome = false;
GroupByLocation = false;
}
});
}

Expand Down Expand Up @@ -162,10 +184,28 @@ public bool GroupByLocation
}
}

private bool _groupByCategory;
public bool GroupByCategory
{
get => _groupByCategory;
set
{
if (_groupByCategory == value)
{
return;
}

_groupByCategory = value;
OnPropertyChanged();
}
}

public CommandBase SetOutcomeGroupingCommand { get; }

public CommandBase SetLocationGroupingCommand { get; }

public CommandBase SetCategoryGroupingCommand { get; }

public long TotalDuration { get; private set; }

public RunAllTestsCommand RunAllTestsCommand { get; }
Expand Down Expand Up @@ -195,6 +235,8 @@ public bool GroupByLocation

public CommandBase RunSelectedTestCommand { get; }

public CommandBase RunSelectedCategoryTestsCommand { get; }

public CommandBase OpenTestSettingsCommand { get; }

private void OpenSettings(object param)
Expand Down Expand Up @@ -382,6 +424,33 @@ private void ExecuteCopyResultsCommand(object parameter)
_clipboard.Flush();
}

private void ExecuteRunSelectedCategoryTestsCommand(object obj)
{
EnsureRubberduckIsReferencedForEarlyBoundTests();

Model.ClearLastRun();

var stopwatch = new Stopwatch();
Model.IsBusy = true;

stopwatch.Start();
_testEngine.Run(Model.Tests.Where(test => test.Category == SelectedTest.Category));
stopwatch.Stop();

Model.IsBusy = false;
TotalDuration = stopwatch.ElapsedMilliseconds;
}

private bool CanExecuteRunSelectedCategoryTestsCommand(object obj)
{
if (Model.IsBusy || SelectedItem == null)
{
return false;
}

return ((TestMethod) SelectedItem).Category != "";
}

//KEEP THIS, AS IT MAKES FOR THE BASIS OF A USEFUL *SUMMARY* REPORT
//private void ExecuteCopyResultsCommand(object parameter)
//{
Expand Down
12 changes: 12 additions & 0 deletions Rubberduck.Core/UnitTesting/TestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Linq;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Annotations;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.UI;
Expand Down Expand Up @@ -77,6 +78,17 @@ public TestResult Result
set { _result = value; OnPropertyChanged(); }
}

public string Category
{
get
{
var testMethodAnnotation = (TestMethodAnnotation) Declaration.Annotations
.First(annotation => annotation.AnnotationType == AnnotationType.TestMethod);

return testMethodAnnotation.Category;
}
}

private void HandleAssertCompleted(object sender, AssertCompletedEventArgs e)
{
_assertResults.Add(e);
Expand Down
11 changes: 11 additions & 0 deletions Rubberduck.Parsing/Annotations/TestMethodAnnotation.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Rubberduck.VBEditor;
using System.Collections.Generic;
using System.Linq;

namespace Rubberduck.Parsing.Annotations
{
Expand All @@ -13,6 +14,16 @@ public sealed class TestMethodAnnotation : AnnotationBase
IEnumerable<string> parameters)
: base(AnnotationType.TestMethod, qualifiedSelection)
{
var firstParameter = parameters.FirstOrDefault();
if ((firstParameter?.StartsWith("\"") ?? false) && firstParameter.EndsWith("\""))
{
// Strip surrounding double quotes
firstParameter = firstParameter.Substring(1, firstParameter.Length - 2);
}

Category = string.IsNullOrWhiteSpace(firstParameter) ? "" : firstParameter;
}

public string Category { get; }
}
}
9 changes: 9 additions & 0 deletions Rubberduck.Resources/RubberduckUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Rubberduck.Resources/RubberduckUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1291,4 +1291,7 @@ NOTE: Restart is required for the setting to take effect.</value>
<data name="Settings" xml:space="preserve">
<value>Settings</value>
</data>
<data name="GroupingStyle_ByCategory" xml:space="preserve">
<value>By category</value>
</data>
</root>
18 changes: 18 additions & 0 deletions Rubberduck.Resources/UnitTesting/TestExplorer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Rubberduck.Resources/UnitTesting/TestExplorer.resx
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,10 @@
<data name="Command_AddTestModule_Error" xml:space="preserve">
<value>Unable to create test module. The host application may not allow for creation of new modules or the project may be locked. For details, check the log.</value>
</data>
<data name="TestExplorer_RunSelectedCategoryTests" xml:space="preserve">
<value>Selected Category</value>
</data>
<data name="TestExplorer_CategoryName" xml:space="preserve">
<value>Category Name</value>
</data>
</root>

0 comments on commit 65b96df

Please sign in to comment.