Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Ability to filter tests #68

Open
pellet opened this issue Jun 28, 2018 · 1 comment
Open

Ability to filter tests #68

pellet opened this issue Jun 28, 2018 · 1 comment

Comments

@pellet
Copy link

pellet commented Jun 28, 2018

The functionality to filter tests with a string the same as you would with the xunit ''filter" parameter, or basic string matching would be great for doing TDD on platform specific code and for kicking off particular suites of tests without needing to separate each suite into a new test assembly.
One way to implement this could be to expose a "RunnerOptions.Filter" property which if set will populate the SearchQuery entry.
If the "RunnerOptions.AutoStart" is set to true it will execute the RunFilteredTestsCommand button rather than the RunAllTestsCommand button.

@pellet
Copy link
Author

pellet commented Jul 19, 2018

Here's a hack I used to get it working using reflection,
I just called this method from the MainActivity.OnCreate method.

    /// <summary>
    /// Kick off your test/tests by using a filter.
    /// </summary>
    /// <param name="filter"></param>
    public void AutoStartFilteredTests(string filter)
    {
        var navigationPage = Xamarin.Forms.Application.Current.MainPage as NavigationPage;
        var homeView = navigationPage.RootPage;
        var homeViewModel = homeView.BindingContext as HomeViewModel;
        Observable
            .FromEventPattern<EventArgs>(homeViewModel, nameof(homeViewModel.ScanComplete))
            .Subscribe(_ =>
            {
                var testAssemblyViewModel = homeViewModel.TestAssemblies.First();
                testAssemblyViewModel.SearchQuery = filter;
                
                var filteredTests = testAssemblyViewModel
                    .GetNonPublicFieldValue<INotifyCollectionChanged>("filteredTests");
                
                Observable
                    .FromEventPattern<NotifyCollectionChangedEventArgs>(filteredTests, nameof(filteredTests.CollectionChanged))
                    .Where(__ => testAssemblyViewModel.RunFilteredTestsCommand.CanExecute(null))
                    .Do(__ => testAssemblyViewModel.RunFilteredTestsCommand.Execute(null))
                    .Subscribe();
                
                //TODO:after test runs
                //System.Environment.Exit(0);
            });
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants