integration-testing

Integration Testing Skill

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "integration-testing" with this command: npx skills add hack23/cia/hack23-cia-integration-testing

Integration Testing Skill

Purpose

Test component interactions, database operations, and external API integrations using Spring testing framework with TestContainers.

When to Use

  • ✅ Testing repository layer with real database

  • ✅ Testing REST API endpoints (if applicable)

  • ✅ Testing Spring Security configuration

  • ✅ Testing external API integrations

Spring Integration Test Patterns

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ApplicationContext.class) @Sql(scripts = "/test-data.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public class PoliticianIntegrationTest {

@Autowired
private PoliticianRepository repository;

@Test
void shouldCreatePoliticianViaApi() {
    // Arrange
    PoliticianRequest request = new PoliticianRequest("John", "Doe", "S");
    
    // Act
    ResponseEntity<Politician> response = restTemplate.postForEntity(
        "/api/politicians",
        request,
        Politician.class
    );
    
    // Assert
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED);
    assertThat(response.getBody()).isNotNull();
    
    // Verify in database
    Politician saved = repository.findById(response.getBody().getId()).orElseThrow();
    assertThat(saved.getFirstName()).isEqualTo("John");
}

}

TestContainers for PostgreSQL

@Testcontainers @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = ApplicationContext.class) public class DatabaseIntegrationTest {

@ClassRule
public static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15")
    .withDatabaseName("cia_test")
    .withUsername("test")
    .withPassword("test");

@BeforeClass
public static void setupTestDatabase() {
    System.setProperty("spring.datasource.url", postgres.getJdbcUrl());
    System.setProperty("spring.datasource.username", postgres.getUsername());
    System.setProperty("spring.datasource.password", postgres.getPassword());
}

@Test
public void shouldConnectToDatabase() {
    assertThat(postgres.isRunning()).isTrue();
}

}

Security Integration Tests

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {ApplicationContext.class, SecurityConfig.class}) @WebAppConfiguration public class SecurityIntegrationTest {

@Autowired
private WebApplicationContext context;

private MockMvc mockMvc;

@Before
public void setup() {
    mockMvc = MockMvcBuilders
        .webAppContextSetup(context)
        .apply(springSecurity())
        .build();
}

@Test
@WithMockUser(roles = "ADMIN")
public void shouldAllowAdminAccess() throws Exception {
    mockMvc.perform(get("/api/admin/users"))
        .andExpect(status().isOk());
}

@Test
public void shouldDenyUnauthenticatedAccess() throws Exception {
    mockMvc.perform(get("/api/admin/users"))
        .andExpect(status().isUnauthorized());
}

}

References

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

secrets-management

No summary provided by upstream source.

Repository SourceNeeds Review
General

incident-response

No summary provided by upstream source.

Repository SourceNeeds Review
General

ai governance

No summary provided by upstream source.

Repository SourceNeeds Review