Back to Repositories

Testing Spring Boot Property Configuration in spring-boot-examples

This test suite evaluates the configuration properties handling in a Spring Boot application using NeoProperties. It validates custom property mappings and basic Map operations in a Spring context environment.

Test Coverage Overview

The test suite covers property injection and validation through Spring Boot’s configuration mechanism.

Key functionality includes:
  • Verification of injected title and description properties
  • Basic Map operations testing
  • Spring context property binding validation

Implementation Analysis

The testing approach utilizes Spring Boot’s test framework with JUnit integration. The implementation leverages @SpringBootTest for full application context loading and @RunWith(SpringRunner.class) for Spring test execution.

Key patterns include dependency injection testing and property value assertion verification.

Technical Details

Testing tools and configuration:
  • JUnit 4 test framework
  • Spring Boot Test context
  • SpringRunner test executor
  • Autowired property injection
  • HashMap implementation for Map testing

Best Practices Demonstrated

The test suite demonstrates several testing best practices including proper test isolation, clear test method naming, and effective use of Spring Boot’s testing annotations.

Notable practices:
  • Separate test methods for distinct functionality
  • Proper assertion usage
  • Spring context configuration
  • Clean test organization

ityouknow/spring-boot-examples

spring-boot-web/src/test/java/com/neo/web/ProPertiesTest.java

            
package com.neo.web;

import java.util.HashMap;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.neo.util.NeoProperties;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ProPertiesTest {

	@Autowired
    private NeoProperties neoProperties;

    @Test
    public void getHello() throws Exception {
    	System.out.println(neoProperties.getTitle());
        Assert.assertEquals(neoProperties.getTitle(), "纯洁的微笑");
        Assert.assertEquals(neoProperties.getDescription(), "分享生活和技术");
    }

    @Test
    public void testMap() throws Exception {
    	Map<String, Long> orderMinTime=new HashMap<String, Long>();
    	orderMinTime.get("123");
    }

}