What happened to Assert.DoesNotThrowAsync() in xUnit?

I just wanted to update the answer with current information (Sep 2019). As Malcon Heck mentioned, using the Record class is preferred. Looking at xUnit’s Github, I see that a current way to check for lack of exceptions thrown is like this [Fact] public async Task CanDeleteAllTempFiles() { var exception = await Record.ExceptionAsync(() => DocumentService.DeleteAllTempDocuments()); … Read more

Populate IConfiguration for unit tests

You can use MemoryConfigurationBuilderExtensions to provide it via a dictionary. using Microsoft.Extensions.Configuration; var myConfiguration = new Dictionary<string, string> { {“Key1”, “Value1”}, {“Nested:Key1”, “NestedValue1”}, {“Nested:Key2”, “NestedValue2”} }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(myConfiguration) .Build(); The equivalent JSON would be: { “Key1”: “Value1”, “Nested”: { “Key1”: “NestedValue1”, “Key2”: “NestedValue2” } } The equivalent Environment Variables would be … Read more

Is there a set of “Lorem ipsums” files for testing character encoding issues?

The Wikipedia article on diacritics is pretty comprehensive, unfortunately you have to extract these characters manually. Also there might exist some mnemonics for each language. For instance in Polish we use: Zażółć gęślą jaźń which contains all 9 Polish diacritics in one correct sentence. Another useful search hint are pangrams: sentences using every letter of … Read more

Pass complex parameters to [Theory]

There are many xxxxData attributes in XUnit. Check out for example the MemberData attribute. You can implement a property that returns IEnumerable<object[]>. Each object[] that this method generates will be then “unpacked” as a parameters for a single call to your [Theory] method. See i.e. these examples from here Here are some examples, just for … Read more

xUnit : Assert two List are equal?

2021-Apr-01 update I recommend using FluentAssertions. It has a vast IntelliSense-friendly assertion library for many use cases including collections collection.Should().Equal(1, 2, 5, 8); collection.Should().NotEqual(8, 2, 3, 5); collection.Should().BeEquivalentTo(8, 2, 1, 5); Original answer xUnit.Net recognizes collections so you just need to do Assert.Equal(expected, actual); // Order is important You can see other available collection assertions … Read more

Python unittests in Jenkins?

sample tests: tests.py: # tests.py import random try: import unittest2 as unittest except ImportError: import unittest class SimpleTest(unittest.TestCase): @unittest.skip(“demonstrating skipping”) def test_skipped(self): self.fail(“shouldn’t happen”) def test_pass(self): self.assertEqual(10, 7 + 3) def test_fail(self): self.assertEqual(11, 7 + 3) JUnit with pytest run the tests with: py.test –junitxml results.xml tests.py results.xml: <?xml version=”1.0″ encoding=”utf-8″?> <testsuite errors=”0″ failures=”1″ name=”pytest” … Read more