xunit

.net core 2.0 ConfigureLogging xunit test

你离开我真会死。 提交于 2019-12-03 12:38:36
问题 In my xUnit integration test in my .NET Core 2.0 project I cannot see log messages in the terminal that also prints the test results. When the code is run in WebHost environment, the logs are printed out to the console. This is how I configure logging in the test's constructor: var config = new ConfigurationBuilder() .AddJsonFile("appsettings.Tests.json") .Build(); var services = new ServiceCollection(); services.AddLogging(options => { options.AddConfiguration(config.GetSection("Logging"));

xUnit theory test using generics

十年热恋 提交于 2019-12-03 10:50:43
In xUnit I can have a Theory test that uses generics in this form: [Theory] [MemberData(SomeScenario)] public void TestMethod<T>(T myType) { Assert.Equal(typeof(double), typeof(T)); } public static IEnumerable<object[]> SomeScenario() { yield return new object[] { 1.23D }; } Which will give me the generic T parameter as double . Is it possible to use MemberData to specify the generic type parameter for a test with a signature like: [Theory] [MemberData(SomeTypeScenario)] public void TestMethod<T>() { Assert.Equal(typeof(double), typeof(T)); } If it is not possible with MemberData or any other

How to test for exceptions thrown using xUnit, SubSpec and FakeItEasy

不羁的心 提交于 2019-12-03 10:37:48
I’m using xUnit, SubSpec and FakeItEasy for my unit tests. I’ve so far created some positive unit tests like the following: "Given a Options presenter" .Context(() => presenter = new OptionsPresenter(view, A<IOptionsModel>.Ignored, service)); "with the Initialize method called to retrieve the option values" .Do(() => presenter.Initialize()); "expect the view not to be null" .Observation(() => Assert.NotNull(view)); "expect the view AutoSave property to be true" .Observation(() => Assert.True(view.AutoSave)); But now I want to write some negative unit tests and check that certain methods don't

Using ReSharper, how to show debug output during a long-running unit test?

大城市里の小女人 提交于 2019-12-03 06:32:49
问题 I'm using xUnit with the ReSharper test runner and the xUnitContrib resharper plugin. When I have a long-running test, I'd like to be able to output some progress indicator to the Unit Test Output window. I've tried Debug.WriteLines , Trace.WriteLine and Console.WriteLine . All of which have the same behavior - nothing shows in the output window until the test has completed. For example: [Fact] public void Test() { Debug.WriteLine("A"); Trace.WriteLine("B"); Console.WriteLine("C"); Thread

How to attach message to rspec check?

北城以北 提交于 2019-12-03 04:43:36
问题 In rspec: Can I attach a message to a check the same way as I would do in xUnit style test frameworks? How? assert_equal value1, value2, "something is wrong" 回答1: should and should_not take a second argument ( message ) that overrides the matcher’s default message. 1.should be(2), 'one is not two!' The default messages are usually pretty useful though. update: for RSpec 3: expect(1).to eq(2), "one is not two!" 回答2: In RSpec, it's the matcher's job to print a sensible failure message. The

How to run setup code only once in an xUnit.net test

一世执手 提交于 2019-12-03 04:35:35
I'm trying to setup my tests using Xunit. I have a requirement to delete all images in a folder start of the tests, and then each method does some image resizing and saves a copy of it's output to the folder. The folder should only be emptied once, and then each method will save their own image into the folder. When I use IUseFixture<T> , the ClearVisualTestResultFolder function is still being called before every test, so I only end up with one image in the folder. public class Fixture { public void Setup() { ImageHelperTest.ClearVisualTestResultFolder(); } } public class ImageHelperTest :

How to implement XUnit descriptive Assert message?

雨燕双飞 提交于 2019-12-03 04:31:11
Context in XUnit github I found this: Add Assert.Equal(expected, actual, message) overload #350 (so a developer ask for a non existing overload see below) Quote from the answer: We are a believer in self-documenting code; that includes your assertions. (so the XUnit team rejects it) OK, I got it. I also believe the self documenting code. Still I can not find out this use case: Sample // Arrange // Create some external soap service client and its wrapper classes // Act // client.SomeMethod(); // Assert // Sorry, soap service's interface, behaviour and design is *given* // So I have to check if

What's the idiomatic way to verify collection size in xUnit?

隐身守侯 提交于 2019-12-03 04:08:11
I have in my test suite a test that goes something like this: [Fact] public void VerifySomeStuff() { var stuffCollection = GetSomeStuff(); Assert.Equal(1, stuffCollection.Count()); } This test works as I expect, but when I run it xUnit prints a warning: warning xUnit2013: Do not use Assert.Equal() to check for collection size. However, no alternative is suggested in the warning, and a google search takes me to the source code in xUnit for the test that verifies this warning is printed. If Assert.Equal() isn't the correct way to verify the lenght of a collection, what is? To clarify: I realize

boost unit tests with xUnit Plugin in Jenkins do not work

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am not a C programmer, but i have to run boost tests on my Jenkins. Now I have installed the xUnit plugin in Jenkins. I added a post-build action : "Publish xUnit test result report" Then, in this post-build step I added : "BoostTest-1.x (default)" Now I have the following options to set: https://www.dropbox.com/s/wxcny55rz2bqk6r/boost_jenkins_options.png The options I set are random, so please help me, I don't understand anything and I didn't find some tutorials. I have not worked with boost unit test and not with the xUnit Jenkins plugin

Dependency Injection with XUnit and ASP.NET Core 1.0

匿名 (未验证) 提交于 2019-12-03 03:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to figure out how I can use dependency injection with XUnit. My goal is to be able to inject my ProductRepository into my test class. Here is the code I am trying: public class DatabaseFixture : IDisposable { private readonly TestServer _server; public DatabaseFixture() { _server = new TestServer(TestServer.CreateBuilder().UseStartup<Startup>()); } public void Dispose() { // ... clean up test data from the database ... } } public class MyTests : IClassFixture<DatabaseFixture> { DatabaseFixture _fixture; public ICustomerRepository