• Stars
    star
    157
  • Rank 238,399 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run xUnit test cases in parallel

By default, xUnit runs all test cases in a test class synchronously. This package extends the default test framework to execute tests in parallel.

dotnet add package Meziantou.Xunit.ParallelTestFramework

By default, all tests will run in parallel. Selectively disable parallelization by adding the DisableParallelization attribute to a collection or theory.

// All tests are run in parallel
public class ParallelTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);

    [Theory]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test3(int value) => Thread.Sleep(2000);

    // This test runs in parallel with other tests
    // However, its test cases are run sequentially
    [Theory]
    [DisableParallelization]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test4(int value) => Thread.Sleep(2000);
}

// This collection runs in parallel with other collections
// However, its tests cases are run sequentially
[DisableParallelization]
public class SequentialTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);
}

Previous versions of this package relied on built in xUnit attributes instead of exposing a dedicated DisableParallelization attribute. For backwards compatibility, parallelization can also be disabled by adding an explicit Collection attribute or Theory attribute with DisableDiscoveryEnumeration enabled.

// All tests are run in parallel
public class ParallelTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);

    [Theory]
    [InlineData(0), InlineData(1), InlineData(2)]
    public void Test3(int value) => Thread.Sleep(2000);

    // This test runs in parallel with other tests
    // However, its test cases are run sequentially because of DisableDiscoveryEnumeration
    [Theory]
    [MemberData(nameof(GetData), DisableDiscoveryEnumeration = true)]
    public void Test4(int value) => Thread.Sleep(2000);

    public static TheoryData<int> GetData() =>  new() { { 0 }, { 1 } };
}

// This collection runs in parallel with other collections
// However, its tests cases are run sequentially because the Collection is explicit
[Collection("Sequential")]
public class SequentialTests
{
    [Fact]
    public void Test1() => Thread.Sleep(2000);

    [Fact]
    public void Test2() => Thread.Sleep(2000);
}

The code is greatly inspired by the sample from Travis Mortimer: xunit/xunit#1986 (comment)

More Repositories

1

Meziantou.Analyzer

A Roslyn analyzer to enforce some good practices in C#.
C#
921
star
2

Meziantou.Framework

C#
644
star
3

WebCrawler

C#
56
star
4

Meziantou.Polyfill

C#
40
star
5

Meziantou.DotNet.CodingStandard

A package to configure .NET coding style and static analysis.
C#
32
star
6

Meziantou.Backup

Copy your files from a source to a destination. For instance you can copy your local files to your OneDrive account or an external disk.
C#
30
star
7

WPFFontAwesome

Use FontAwesome in WPF application
C#
25
star
8

Meziantou.OneDrive

C#
21
star
9

UnlockFile

C#
18
star
10

meziantou.moneiz

C#
15
star
11

Window-Manager

C#
14
star
12

PasswordManager

TypeScript
13
star
13

ExportTable

Export a list of objects to Excel (xlsx), HTML table or CSV
C#
13
star
14

CSharpProjectTemplate

C#
13
star
15

online-tools

HTML
10
star
16

Meziantou.FluentAssertionsAnalyzers

C#
10
star
17

Meziantou.AspNetCore.BundleTagHelpers

C#
8
star
18

Uncss.Net

C#
7
star
19

GoldParser-Engine

C#
7
star
20

DepsUpdater

Update project dependencies
C#
7
star
21

Meziantou.GitLabClient

.NET client for GitLab API
C#
7
star
22

editorconfig

6
star
23

Meziantou.DataGenerator

C#
6
star
24

Meziantou.AvatarGenerator

Generate an avatar using the initials of your name.
C#
6
star
25

exportsrc

C#
6
star
26

IssuesToRss

Create an RSS feed from GitHub issues
C#
5
star
27

Meziantou.AspNetCore

C#
5
star
28

EditorconfigGeneratorForAnalyzers

C#
3
star
29

websearcher

C#
3
star
30

Resources-Editor

C#
3
star
31

OpenExchangeRatesClient

C#
3
star
32

Samples

C#
3
star
33

OneDriveBackup

C#
3
star
34

HttpCache

Cache http requests
C#
3
star
35

SampleNuGet

C#
3
star
36

File-Integrity-Monitor

C#
2
star
37

Meziantou.HtmlLocalizer

C#
2
star
38

PdfTools

C#
2
star
39

typescript-utilities

TypeScript
2
star
40

DocumentScanner

C#
2
star
41

SwissKnife

C#
2
star
42

Meziantou.CodeDom

C#
2
star
43

Recompress

C#
2
star
44

Meziantou.GitLab.TestLogger

C#
2
star
45

show-me-english-browser-extensions

JavaScript
1
star
46

CsvFileSplitter

Split large CSV file into smaller ones
C#
1
star
47

Meziantou.WLW.CodeEditor

C#
1
star
48

WordPress-Blob-Exporter

WordPress allows to export blog data but this export does not include blob data. This is what this tool is for, get an offline copy of blobs.
C#
1
star
49

Meziantou.TfsBackup

C#
1
star
50

Alternate-Data-Stream

C#
1
star
51

WordGenerator

Generate words using Markov chain
C#
1
star
52

Yasher-Yet-Another-Hasher-

C#
1
star
53

Yet-Another-Regex-Tester

C#
1
star
54

meziantou

1
star
55

repro-reproduciblebuilds

C#
1
star
56

prebuilt

1
star
57

playground

1
star
58

MongoDBInstance

Spawn instances of MongoDB. Useful for testing.
C#
1
star
59

Meziantou.MSBuild.Tools

C#
1
star