Integration testing controller action fails to cre...
# help-with-umbraco
c
I was following the guide on unit testing https://docs.umbraco.com/umbraco-cms/implementation/integration-testing#testing-from-controller-to-database after getting to the point around setting up unit tests for a controller, I had setup a tetsing project as per the guide (with the UmbracoTestServerTestBase) and created a class that inherits from UmbracoTestServerTestBase with a single blank test,:
Copy code
c#
    [TestFixture]
    public class UsersControllerTests : UmbracoTestServerTestBase
    {
        [Test]
        public async Task EnsureSuccessStatusCode()
        {
        }
    }
This seems to fail every time, showing a load of services failed to be created:
Copy code
System.AggregateException : Some services are not able to be constructed
If I change the inherited type to UmbracoIntegrationTest this however runs fine. Is there extra steps I am missing to get this to work?
I had a go at recreating this in a blank project, I seem to get an error:
Copy code
System.InvalidOperationException : Can't find 'C:\Development\LearningUmbraco\MyProject.IntegrationTests\bin\Debug\net7.0\Umbraco.Tests.Integration.deps.json'. This file is required for functional tests to run properly. There should be a copy of the file on your source project bin folder. If that is not the case, make sure that the property PreserveCompilationContext is set to true on your project file. E.g '<PreserveCompilationContext>true</PreserveCompilationContext>'. For functional tests to work they need to either run from the build output folder or the Umbraco.Tests.Integration.deps.json file from your application's output directory must be copied to the folder where the tests are running on. A common cause for this error is having shadow copying enabled when the tests run.
I tried setting
<PreserveCompilationContext>true</PreserveCompilationContext>
in my csproj, this didn't make a difference, there doesn't seem to be a
Umbraco.Tests.Integration.deps.json
, I have noticed there's an active GH bug https://github.com/umbraco/Umbraco-CMS/issues/14554 that says the file instead named for some reason
{MyProjectsName}.deps.json
, I have checked and there is a file by that name, I will try and just rename this file and see how that works.
It worked, making a note that for now to get Umbraco integration tests to run you need to rename the file
bin/Debug/{.net version}/{your project name}.deps.json
to
Umbraco.Tests.Integration.deps.json
d
Hi @crashtestdev Glad you found the solution by yourself! I'm wondering, how are you going to use the integration tests? I'm asking because it seems to me that Umbraco only supports Isolated integration tests. I would like to use an existing database-connection to setup my integration tests but i can not get this to work and i find the documentation too brief on this point. I already created a github issue for this: https://github.com/umbraco/UmbracoDocs/issues/5834#issuecomment-1931943039
l
If I'm not mistaken, the
UmbracoTestServerTestBase
thing starts a webserver, so you'll have to call the controllers to interact with it. The services will be there in the hosted code. If you want to test your code "in process" with the tests, you'll wanna use the
UmbracoIntegrationTest
base.
40 Views