Hello @Narvekar, Sharvari,
Welcome to Microsoft Q&A forum.
Based on my test, it should work. Just to confirm, you are testing this locally or using Azure/Azure DevOps? And your Unit Test project is based on .NET Framework not .NET/.NET Core right?
You may need to confirm these things:
- The app.config/App.config file is included in the Unit Test project. If it’s not included in the Unit Test project, please click "Show All Files" button in VS Solution Explorer > find the displayed app.config/App.config file > right-click it > Include in Project > Clean, rebuild and run your test.
- Double check and confirm that the app.config/App.config file is stored in the Unit Test project folder, and make sure that the key was set in this file. Also please make sure that the <appSettings></appSettings> was set between
<configuration>
and</configuration>
. - If you are testing in Azure, please try to confirm that it works well locally.
- If you are using .NET Framework based project(Unit Test), and above suggestions don’t work, please try to create a new Unit Test project, and add a new app.config file, include it in the project. Add the <appSettings> into the app.config file and write the unit test case then run the test. If the same error appeared this time, please share the detailed steps with us to reproduce this issue and check further.
BTW, are you using Visual Studio 2022?
Feel free to contact us.
Best Regards,
Tianyu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.