I would suggest moving set-up stage to a constructor to avoid having initialization code inside every test. xUnit creates a new instance of test class for every test, so that tests won't share any state between each other, but it saves you from a lot of boilerplaiting.
Thank you @RawCoding, what have you used as reference if anything at all, for the conceptual understanding of integration testing and then potentially for the implementation?
I am testing something similar but I want to test a case with getting null data from my collection when there will be do data at the db collection. But as the tests running in parallel, my tests are overlapping and failing randomly. I have different class fixtures for these but all are accessing same db and collection. Is there any way to perform this without disabling the parallelisation ?
Brilliant job mate! I would like to make a small request. Could you do a video going through different collections like concurrent collection and async collections if that’s ok. Thanks
@@RawCoding Most things in the real world are not basic CRUD or return a nice value wrapped in a bow. At some point, all of your units need to be strung together to perform a complex task and that rarely can be tested by returning a simple value.
Clearly a mistake has been made if it’s not simple, but I’m aware that happens all the time, heck even I’ve lived through it countless times. Do check the next 2 videos where you can find more ‘complex’ examples, where I show how to test with identity mocking and I think it’s making sure emails gets sent to admins and managers.
How do i test methods that require httprequest results after a login from external sources => afterwards the test method calls a production database to save records. Is this kind of method untestable? I can't make the database in memory because the code in submethod defines the connectionstring and so on... Can i write tests for production environment?
@@RawCoding That's exciting, recently I am building an asp.net core web api, I know I should create the test for the controller, but I don't really know how. Appreciate!
add this code to CreateDatabase() and forget for existing db exception bool exists; var commandExists = @$"select exists( SELECT datname FROM pg_catalog.pg_database WHERE lower(datname) = lower('{db}'));"; await using (var c = new NpgsqlCommand(commandExists, connection)) { exists = (bool) await c.ExecuteScalarAsync(); } if (exists) return;
I would suggest moving set-up stage to a constructor to avoid having initialization code inside every test. xUnit creates a new instance of test class for every test, so that tests won't share any state between each other, but it saves you from a lot of boilerplaiting.
Great tutorial as always! Thank you for your work ^^
Cheers)
Excatly what I was looking for, thanks for the great content.
Thank you @RawCoding, what have you used as reference if anything at all, for the conceptual understanding of integration testing and then potentially for the implementation?
Also convinient option is to have database server running in docker container.
I am testing something similar but I want to test a case with getting null data from my collection when there will be do data at the db collection. But as the tests running in parallel, my tests are overlapping and failing randomly. I have different class fixtures for these but all are accessing same db and collection. Is there any way to perform this without disabling the parallelisation ?
Brilliant job mate! I would like to make a small request. Could you do a video going through different collections like concurrent collection and async collections if that’s ok. Thanks
What do you mean collections? As in the tests them selfs?
@@RawCoding no not test just a video on different types of collections like the video you did with ienumerable
Aha is there specific thing that you are confused about or why do you think you need a tutorial about that?
@@RawCoding it be a good reminder recently I looked at concurrent collections and sometimes I get confused on what each one does.
Testing return values is easy. Testing a method which performs a whole bunch of tasks is where this falls over.
Well you’ve pretty much resolved the problem in the 2nd sentence with the 1st
@@RawCoding Most things in the real world are not basic CRUD or return a nice value wrapped in a bow. At some point, all of your units need to be strung together to perform a complex task and that rarely can be tested by returning a simple value.
Clearly a mistake has been made if it’s not simple, but I’m aware that happens all the time, heck even I’ve lived through it countless times. Do check the next 2 videos where you can find more ‘complex’ examples, where I show how to test with identity mocking and I think it’s making sure emails gets sent to admins and managers.
can you do some videos on design patterns?
We shall
@@RawCoding oo and possibly SOLID. Thanks so much
Enough SOLID, roll GoF patterns on 🤪
@@algarud why not both?
Can do both )
How do i test methods that require httprequest results after a login from external sources => afterwards the test method calls a production database to save records. Is this kind of method untestable? I can't make the database in memory because the code in submethod defines the connectionstring and so on... Can i write tests for production environment?
It’s hard to tell from that description. You can make methods virtual and have your mock override them and return dummy data
So it's a unit test structure with integration testing functions. Is that it?
Yes
Dude, your email notifications are making me crazy! I am not able to find my own emails.
Which emails?
17:01
23:19
24:36
24:45
24:50
And probably more :p
@@RawCoding
It's an awesome tutorial, I am still not very clear, for example, how should we test an asp.net Core Web API? What can we mock?
It’s coming son don’t worry
@@RawCoding That's exciting, recently I am building an asp.net core web api, I know I should create the test for the controller, but I don't really know how. Appreciate!
We test the controller in this video, what kind of test do you have in mind?
@@RawCoding like those http endpoints
So you want to test via http call rather than calling a method?
add this code to CreateDatabase() and forget for existing db exception
bool exists;
var commandExists = @$"select exists(
SELECT datname FROM pg_catalog.pg_database
WHERE lower(datname) = lower('{db}'));";
await using (var c = new NpgsqlCommand(commandExists, connection))
{
exists = (bool) await c.ExecuteScalarAsync();
}
if (exists) return;
Good job Thank you
but fast-paced teaching could not help much as we need to pause the video too many times
Cheers, it’s a hard balance to strike
👍🏽
Cheers
Found it