Exemplo n.º 1
0
    public static async Task <int> RunTests(Func <TestFilter?, TestSummary> runTestsCallback, string assemblyName, string?filter)
    {
        ApplicationEntryPoint?entryPoint = null;

        if (OperatingSystem.IsAndroid())
        {
            entryPoint = new AndroidEntryPoint(new SimpleDevice(assemblyName), runTestsCallback, assemblyName, filter);
        }
        if (OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS())
        {
            entryPoint = new AppleEntryPoint(new SimpleDevice(assemblyName), runTestsCallback, assemblyName, filter);
        }
        if (OperatingSystem.IsBrowser())
        {
            entryPoint = new WasmEntryPoint(runTestsCallback, assemblyName, filter);
        }
        if (entryPoint is null)
        {
            throw new InvalidOperationException("The XHarness runner library test runner is only supported on mobile+wasm platforms. Use the XUnitWrapperLibrary-based runner on desktop platforms.");
        }
        bool anyFailedTests = false;

        entryPoint.TestsCompleted += (o, e) => anyFailedTests = e.FailedTests > 0;
        await entryPoint.RunAsync();

        return(anyFailedTests ? 1 : 0);
    }
Exemplo n.º 2
0
    public static async Task <int> RunTests(
        Func <TestFilter?,
              TestSummary> runTestsCallback,
        string assemblyName,
        string?filter,
        HashSet <string> testExclusionList)
    {
        // If an exclusion list is passed as a filter, treat it as though no filter is provided here.
        if (filter?.StartsWith("--exclusion-list=") == true)
        {
            filter = null;
        }
        ApplicationEntryPoint?entryPoint = null;

        if (OperatingSystem.IsAndroid())
        {
            entryPoint = new AndroidEntryPoint(new SimpleDevice(assemblyName), runTestsCallback, assemblyName, filter, testExclusionList);
        }
        if (OperatingSystem.IsMacCatalyst() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS())
        {
            entryPoint = new AppleEntryPoint(new SimpleDevice(assemblyName), runTestsCallback, assemblyName, filter, testExclusionList);
        }
        if (OperatingSystem.IsBrowser())
        {
            entryPoint = new WasmEntryPoint(runTestsCallback, assemblyName, filter, testExclusionList);
        }
        if (entryPoint is null)
        {
            throw new InvalidOperationException("The XHarness runner library test runner is only supported on mobile+wasm platforms. Use the XUnitWrapperLibrary-based runner on desktop platforms.");
        }
        bool anyFailedTests = false;

        entryPoint.TestsCompleted += (o, e) => anyFailedTests = e.FailedTests > 0;
        await entryPoint.RunAsync();

        if (OperatingSystem.IsBrowser())
        {
            // Browser expects all xharness processes to exit with 0, even in case of failure
            return(0);
        }
        return(anyFailedTests ? 1 : 0);
    }