C
C#8mo ago
Gipper

Can I set up an integration testing environment with no app available and no code? If so, how?

Right now I have a test solution set up for ASP.NET and I can't launch it because it says WebServer failed to listen on port port_number. I am trying to use XUnit now:
public class TestesIntegracaoUser : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
private const string URLBase = "http://User";

public TestesIntegracaoUser(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
//Actual test code
}
public class TestesIntegracaoUser : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
private const string URLBase = "http://User";

public TestesIntegracaoUser(WebApplicationFactory<Program> factory)
{
_factory = factory;
}
//Actual test code
}
I thought that WebApplicationFactory should have generated a web server for testing, but it's not doing so. I need it so I can debug this code, if I can.
28 Replies
Lex Li
Lex Li8mo ago
For ASP.NET Core, you can build integration test cases around Kestrel, but for ASP.NET 4.x your option is limited to IIS Express or local IIS.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Lex Li
Lex Li8mo ago
"without IIS or IIS Express" is only applicable to ASP.NET Web API/SignalR on OWIN self hosting, but not general ASP.NET 4.x on System.Web.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX8mo ago
TeBeCo
there's absolutly no need of IIS / IIS express if you're using Topshelf / Owin / Webapi2
React with ❌ to remove this embed.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Lex Li
Lex Li8mo ago
Sure. Always painful to distinguish the two.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
Like this:
private readonly HttpClient _httpClient;
private readonly WebApplicationFactory<Program> _factory;
private const string URLBase = "http://User";

public TestesIntegracaoUser(WebApplicationFactory<Program> factory)
{
_httpClient = new HttpClient();
_factory = factory;
_httpClient.GetStreamAsync(URLBase);
}
private readonly HttpClient _httpClient;
private readonly WebApplicationFactory<Program> _factory;
private const string URLBase = "http://User";

public TestesIntegracaoUser(WebApplicationFactory<Program> factory)
{
_httpClient = new HttpClient();
_factory = factory;
_httpClient.GetStreamAsync(URLBase);
}
the Program.cs doesn't have anything (no I don't know what I'm doing 😆 🙃), here it is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestesIntegracao
{
public partial class Program
{
protected Program()
{
}
public static async Task Main(string[] args)
{
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestesIntegracao
{
public partial class Program
{
protected Program()
{
}
public static async Task Main(string[] args)
{
}
}
}
here is the .csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.7.1" />
<!--<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />-->
<PackageReference Include="xunit.extensibility.core" Version="2.7.1" />
<InternalsVisibleTo Include="TestesIntegracao" />
</ItemGroup>

<ItemGroup>
<!--<Using Include="NUnit.Framework" />-->
<InternalsVisibleTo Include="TestesIntegracao" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="8.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.7.1" />
<!--<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />-->
<PackageReference Include="xunit.extensibility.core" Version="2.7.1" />
<InternalsVisibleTo Include="TestesIntegracao" />
</ItemGroup>

<ItemGroup>
<!--<Using Include="NUnit.Framework" />-->
<InternalsVisibleTo Include="TestesIntegracao" />
</ItemGroup>

</Project>
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
No, I've just been trying a bunch of stuff to see if it would work. All the weirdness is a product of that experimentation. I was only asked to make the skeletons of the tests, as in just the arrange and assert parts, it's not meant to actually work yet. If I can't debug the code that is a problem, but I'll deal with it What would you expect to find in a Program.cs? In this context...
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
I actually don't know and would like to learn
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
but if there is no existing app, what is the point of that command?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
but these tests are for a different app
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
So, would you say there is a way to set up an integration testing environment with no app?
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
welcome to my life the past two weeks I agree
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
It's a school thing, mine is just the devops part of a 4 part web app project. Two of my colleagues are making the app, but they only have to deliver it by the end of the semester, which is also when I have to deliver the tests for an app that will only exist god knows when. I suppose the people in charge seem to be at least a little understanding of the impracticability of my situation, so that's good, but it is very stupid for sure.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
Nah, I'm not. And their repo doesn't even have anything in it yet.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Gipper
GipperOP8mo ago
Listen, I appreciate your help and I'm sorry to have wasted your time, but I don't think there is any help you can give me at this point. yeah, thanks for clearing it up 🙂
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server