Web config app settings values null during visual studio unit test - visual-studio

I have added new unit test project in VS 2015 for a method in my .net solution, while i run test case, the web config app settings values are null and unable to complete test, Actually the config key values are available and accessible during web app run, but during unit test the values are null,
can anyone please help me out.
Thanks in Advance

Test project needs app.cofig with similar settings present as in web project being tested.
Unit test is run in a separate app domain so needs it's own config file.
The ConfigurationManager reads the config file of the current app domain being run so create an app.config file for the test project and copy the desired configuration settings over to allow the tests to be exercised as expected.
This issue also exposes how your code is tightly coupled to implementation concerns in terms of the using the ConfigurationManager and you should consider abstracting configuration access so that they can be mocked/replaced to allow unit tests to be done in isolation.

Related

Run Spring Boot application with test application.properties

I've just installed Cypress to run e2e tests and that requires my Spring Boot app running so it can plug into the browser to run tests.
I already have an application.properties file under test/resources which creates an H2 memory database populated from a test/resources/data.sql to run my unit and integration tests.
I want to start my app using those test resources so I can run Cypress tests with my testing environment, is that poosible?
I tried changing SPRING_PROFILES_ACTIVE env variable to test but it doesn't take my config files under the test folder, what can I do?
test/resources/application.properties is, as far as I understand it, purely for use in (unit/integration/service) tests that live in test/.
Try creating an additional application-test.properties file in main/resources. This should be used when you have the test Spring profile activated (although it might be better to choose another name for the profile to avoid confusion).

How to unit test classes within a WCF web service

How can I get a unit test project in a (VS2015) solution for a WCF web service to use the same web.config file for its own app.config? I don't want to have to replicate all the settings that are in web.config in my app.config (and have to remember to keep them in sync). Thanks.
I was able to shift the relevant settings to a separate config file using this method. One thing to remember is that paths are relative to the WhateverTests\bin\Debug folder when referring to the other config file in the Whatever project.

How to ignore a java file when maven install

I have a #Service class where i'm caching some table data. I don't want those queries to run while building mvn install. Is there a way to ignore the file while building and it only execute when i start the server ?
It's a spring-boot application.
Here is background of my issue. I have initialized the spring boot app from http://start.spring.io/ site, which actually adds dummy application test file with SpringBootTest annotation and default contextLoads() with Test annotation, with an intention to initialize and execute all test cases, which needs to initialize and execute all code base. In my opinion this is not required, as we can have respective Test classes per controller/manager, which will give more controlled environment to hook up your Test setups and executions.
I have removed the default application Test file and included respective test classes for code coverage and quality. This way my beans are not executed at server startup time rather build time.

Other ways of MVC 3 Asp.net testing

I am currently testing MVC 3 Controller and views using HTML and notepad. Is there other ways to do testing if you cannot modify the code? Like for example creating a seperate project to do testing?
Assuming that you have the capacity to create a test project or two which can tap into the web application, you essentially have to basic tools at your disposal:
Unit tests
Coded UI tests
Unit tests are used to test specific components of your application. If your application has a nice architecture which takes dependency injection into account, there is very little in MVC that you cannot unit test to some extent. The advantage of unit tests is that they help find the source of bugs in your code (as they are small, targeted tests) and that they help prevent regressions when refactoring or adding new functionality.
Coded UI tests are used to test user-facing features in your application and serve as integration tests which allow you to test the entire application stack, including the user interface. They are recorded just like you would record a macro in MS Office.
Both of these can be done nonintrusively. You'll need access to the original solution (or at least the DLLs and a hosted version of the website at the very least.
For more information on unit tests: http://msdn.microsoft.com/en-us/library/dd264975.aspx
For more information on Coded UI tests: http://msdn.microsoft.com/en-us/library/dd286726.aspx

TeamCity - Reporting on success of multiple projects configurations in one place

We currently have TeamCity setup so we have a project per component (Website, APIs, Mobile App, etc). Each project contains a Functional Tests configuration.
All of these components are dependent on the same database, which has migrations applied to it. The migrations are applied before the functional tests run, so problematic migrations cause builds to fail. However to discover which Functional tests fail as a result of a migration we have to manually view each one (we currently have 15+ components, and associated TC projects, so it's not ideal).
In order to be able to see the results of all Functional Test configurations in one place, is it possible to aggregate the results of all the Functional Test configurations into a new project WITHOUT creating templates of the current functional test configurations and setting these up in the new project?

Resources