Remote Testing in Visual Studio 2022 - Run tests in Linux/Windows/WSL in seconds!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi guys my name is karthik and i am from azure automation.com and today we'll be talking about visual studio 2022's new feature which is still an experimental stage which is nothing but the remote testing so this remote testing feature while they were talking about in visual studio to launch which was kind of very interesting because this is one thing which we all were looking for for quite a long time and it is right now available in visual studio right now so what it says is that this functionality is useful for cross-platform developers who deploy code to multiple different target environments such as different windows or linux operating systems for example normally a developer would have to push changes to a ci pipeline to get feedback from the test running on the linux operating system with this feature you can run linux test right from visual studio 202 by connecting the test explorer to a remote environment this is pretty cool so this is available from resource you don't need to update preview 3 or later so if you have the latest version of wisconsin to preview then you should be seeing this particular functionality available for you in order to set up this remote testing within your testing environment it is very very simple all you need to do is you need to have a docker file which actually is going to have all the setup that you actually need for your testing to happen for example you need to have your application up and running and then you need to have your testing environments for example if you're running the synonym test then you need to have the selenium server up and running on that particular container and you need to set up everything on that particular docker file and once you have everything there so you will have an image so then you can use this test environment.json file to invoke the image that you have created and in this case they have mentioned this docker image like mcr.microsoft.com.net core.sdk to run one of their tests and this can be your image basically like the application the selenium thing that was talking about before you should have all those things on that particular created docker image and once you have that you can then run the test straight from the visual studio test explorer which is the cool thing about this particular remote testing feature of visual studio do so let's quickly see how this actually works so all i'm going to do is i'm going to start creating a new project over here and i will show you how it actually can be leveraged so i'm going to use this x unit test project and i'm going to call this as remote debugging i'm going to choose dartmouth version 5. and there we go we have this particular resource we're trying to do with this particular test which is nothing but the x unit test for us over here so this is a super simple test and once you start trying to build this solution you will see this particular test is going to be shown in this particular test explorer so every time while we run any of the test at the moment in this particular test it is going to be running on the windows operating system which is nothing but this host operating system right but this time i'm gonna see what if i could be able to run the same test on a linux operating system i'm not really gonna over complicating by creating a docker file with so many setups and stuff but this video is gonna be super simple and get started so i'll show you how it actually can be done all i'm going to do is i'm going to create a constructor here and i'm going to put the i test output helper which is this one test output helper and then i'm going to create an assign a field so that i can able to access this test output helper over here so i'm just going to say test output helper dot writeline of just going to say string interpolation here test is running in something like that and i'm just gonna say environment dot os version dot do string something like that this is the super simple test that i have got and now if i try running this particular test over here you will see that the test has got passed and it is running on the windows nt operating system right which is nothing but this windows 10 operating system which i'm currently running my test but now i wanted to run the same test on an linux docker container so that i could able to run the same test on a linux operating system instead of just running on the windows operating system if i wanted to run the same test on linux operating system probably i should be doing the wsl2 uh by running a or spinning a container and then doing a docker file i need to create a docker file or docker compose file and then i need to run the test on that particular container but if i wanted to do everything just by clicking it from here on the test explorer then this feature is going to be very very helpful i'll show you how to do that so the first thing which i'm going to do is let me go into this particular directory which is this one and once it is here i'm going to open this in the vs code it's because that's going to be making your life more easier and then i'm going to create a new or docker file here and this docker file is going to hold one of our docker image which i'm probably going to be running uh so that i could able to address that same test to be running on that particular container when it start running it so all i'm going to do is i'm just going to go to the documentation which is shown as over here i'm not going to be ashamed of copying this from here i'm just going to copy this whole docker file details i'm going to paste it over here i'm going to save it and then i also need to create one more file which is nothing but the test environment dot json file and this is the file which is very important to really understand like how it actually works so basically this json file actually starts with version one at the moment i think microsoft has a plan to improve that even further with more advancement later on so this is version one at the moment something like this and then they call this as environments and this is basically like an array type and this environment is where you're gonna place different environments basically so for example you can give a name for this environment and i'm gonna call this as maybe you've been to uh yeah something like that and then if i wanted to uh give a type at the moment the type the support is like docker as well as wsl if you have wsl2 enabled within your machine you can give the type as docker or wsl and i'm going to choose the docker over here and then i need to specify the docker image and this image is nothing but the image which i'm going to be building from this particular docker file that i have so i'm just going to use the same registry to start creating a docker file but the file name or the docker file name that i'm going to be giving while i'm going to run this particular docker file is going to be this one so this is the image name which i'm going to be creating locally within my machine so that's it this is the only one thing which i'm going to be doing but if you wanted to do something like a wsl 2 if you want to have that information within your machine you can do that as well something like this see wsl pin 2 and then you can give the type as wsl and wsl distribution as you've been to over here so this is something you can do it as well it's again up to you like how you really wanted to uh run your test on which environments so these are the two way that you could able to run that apart from your host windows operating system and once i have this i then can start running my test using this environment using the visual studio 202 explorer but we need this particular docker image right i mean i have already built within my machine so if i open the terminal i can show you what i really mean so if i just show my images over here you will see that i already have an image something like the docker core dot net core sdk 3.1 right this is the image that i have i have built already so that i can refer the same docker image which i have built pretty much referring to this particular docker file using this particular sdk right so these are going to be pretty much exactly the same thing i already have and now if you try to go to the visual 2 over here you will see that there is no change at all i mean it looks pretty much exactly the same there is not going to be any way that you can run the test on different environments so where do you specify that it is not going to work i mean i couldn't able to figure out like how and where this particular file is to be sitting basically for the first time well the problem was actually instead of putting your files or the docker file in the test environment.json file on the project level you should be putting these two files on the solution level which is going to be over here so once you do these two files i mean once you put these two files on this particular level you will see that the test explorer is currently running by itself there was some loading happened and let me just scroll this a bit over here you will see that there is going to be a new option coming up for you something like local windows environments by default and then you will have this you've been to and the wsl you've been to which is the two environments that we set in our vs code over here i mean these two files are right now moved that's why it's saying deleted but it is actually sitting which we already know right so now if i wanted to run this particular test let's see what's going to happen so if i go to the docker for windows so this is my docker for windows which is currently running no containers at the moment and now i have chosen the environment as let's say you've been to over here and now if i'm going to run the test you will see that once i started running the test it is running this dotnet core sdk image and it's going to run them as a container within this particular docker for windows and the test execution has been i guess it is completed so let's see what has happened no it does not so it first discovered that which is weird uh let me run this again i think by this time the test has to run yeah the test has been successfully completed running and the container is still running i think it will be deleted later on after some time and then you will see that the test is currently running on the unix operating system instead of the windows operating system so now we saw that we can run the windows operating system on ubuntu operating system and if you have enabled the wsl 2 within your machine you could also run the same test on the wsl 2 as well i mean this way it is going to be very faster because you need to have your wsl with all the ubuntu from the windows store to be installed at the same time you need to enable the wsl2 in your docker for windows if you set up everything it will start running i mean i mean i have not done anything in my machine it is going to not run the moment but this is how you need to set up as well so this is the way that you could run the test on the linux operating system straight away from visual studio 2 using the remote debugging feature of visual studio 2022 once again thank you for watching this video and you guys have a great day
Info
Channel: Execute Automation
Views: 4,641
Rating: undefined out of 5
Keywords: apple, VisualStudio2022, visual Studio, microsoft, executeautomation, testing, qa, first hand experience, introduction, installing, installation and getting started, getting started, apple m1, m1 silicon, silicon, m1, chipset, rosetta, transitioning layer, asp, AspNetCore, minimal api, remote testing
Id: GkSOip-NfTM
Channel Id: undefined
Length: 10min 45sec (645 seconds)
Published: Sun Oct 10 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.