How to apply integration tests to a Flask RESTful API

Flask provides a test_client you can use in your tests: from source.api import app from unittest import TestCase class TestIntegrations(TestCase): def setUp(self): self.app = app.test_client() def test_thing(self): response = self.app.get(“https://stackoverflow.com/”) assert <make your assertion here> Flask Testing Docs

Spring Boot. @DataJpaTest H2 embedded database create schema

I had the same issue, I managed to resolve by creating schema.sql (in resources folder) with the content CREATE SCHEMA IF NOT EXISTS <yourschema> Documentation can be found here but imho the lack of real examples make it very complex. Warning: this script is also executed within the normal (not test) environment. Not mandatory, but … Read more

Xcode project how to detect target programmatically or how to use env vars

Never mind… figured out that it is in “Schemes” that you set this. For example if you want TARGET=TEST to be available during Test and TARGET=RUN to show during run, just set that in your Scheme > Environment Variables > Name/Value. Then from your app you can do: [[[NSProcessInfo processInfo] environment] objectForKey:@”TARGET”] Using build settings … Read more

Set dummy IP address in integration test with Asp.Net Core TestServer

You can write middleware to set custom IP Address since this property is writable: public class FakeRemoteIpAddressMiddleware { private readonly RequestDelegate next; private readonly IPAddress fakeIpAddress = IPAddress.Parse(“127.168.1.32”); public FakeRemoteIpAddressMiddleware(RequestDelegate next) { this.next = next; } public async Task Invoke(HttpContext httpContext) { httpContext.Connection.RemoteIpAddress = fakeIpAddress; await this.next(httpContext); } } Then you can create StartupStub class … Read more

Spring Boot Authentication for Integration Tests

You can try excluding few more auto configurations: @EnableAutoConfiguration(exclude = { org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration.class, org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration.class, org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration.class, org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration.class }) Btw, more elegant way of excluding stuff is by defining application-test.properties in your test sources and marking your test with @Profile(“test”). Then just add this to your config: spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration,org.springframework.boot.autoconfigure.security.SecurityFilterAutoConfiguration,org.springframework.boot.autoconfigure.security.FallbackWebSecurityAutoConfiguration,org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration All the possible configurations that can be excluded you can … Read more

Java, Junit – Capture the standard input / Output for use in a unit test [duplicate]

Use System.setOut() (and System.setErr()) to redirect the output to an arbitrary printstream – which can be one that you read from programmatically. For example: final ByteArrayOutputStream myOut = new ByteArrayOutputStream(); System.setOut(new PrintStream(myOut)); // test stuff here… final String standardOutput = myOut.toString();

How to use WebApplicationFactory in .net6 (without speakable entry point)

Note that if you are trying to use xUnit and its IClassFixture<T> pattern, you will run into problems if you just use the InternalsVisibleTo approach. Specifically, you’ll get something like this: “Inconsistent accessibility: base class WebApplicationFactory<Program> is less accessible than class CustomWebApplicationFactory.” Of course you can solve this by making CustomWebApplicationFactory internal but it only … Read more

Integration testing ASP.NET Core with .NET Framework – can’t find deps.json

We should get “Program” class from the main project but it automatically references Microsoft.AspNetCore.Mvc.Testing.Program class public class VersioningTests : IClassFixture<WebApplicationFactory<Program>> this code must reference our main Program code. So we must put a reference to the Program class on the last line in Program.cs file: public partial class Program { }