프로파일링을 이용하면 좀 더 세부 사항을 얻을 수 있다. 환경 변수를 이용해 커스텀(사용자 정의) 프로파일을 정의할 수 있다. 달리 말하면, 변수 이름을 전달하고 주어진 값과 일치하면 테스트 메서드가 실행된다. 커스텀 프로파일을 생성하려면 예제 7-5에 보인 것처럼 ProfileValueSource 인터페이스를 구현해야 한다.
예제 7-5 CustomProfile.java
package com.apress.isf.spring.test.profile;
import org.springframework.test.annotation.ProfileValueSource;
public class CustomProfile implements ProfileValueSource {
public String get(String key) {
if (key.equals("environment"))
return "dev";
else if (key.equals("os.name"))
return "Unix";
return null;
}
}