Я использую следующий инструмент для запуска встроенного Redis для модульного тестирования. Новый экземпляр сервера Redis. < /p>
@Import({RedisConfiguration.class})
@Service
public class RegistrationService
RedisTemplate redisTemplate = new RedisTemplate(); // ниже. < /p>
...
RedisServer redisServer;
@Autowired
RegistrationService RegistrationService;
@Before
public void Setup() {
redisServer = RedisServer.newRedisServer();
redisServer.start();
}
@Test
public void testSubmitApplicationOverview() {
String body = "{\n" +
" \"VehicleCategory\": \"CAR\",\n" +
" \"EmailAddress\": \"email@email.com\"\n" +
"}";
String result = RegistrationService.SubmitApplicationOverview(body);
Assert.assertEquals("something", result);
}
< /code>
Настройки Redis в application.properties < /strong> < /p>
#Redis Settings
spring.redis.cluster.nodes=slave0:6379,slave1:6379
spring.redis.url= redis://jx-staging-redis-ha-master-svc.jx-staging:6379
spring.redis.sentinel.master=mymaster
spring.redis.sentinel.nodes=10.40.2.126:26379,10.40.1.65:26379
spring.redis.database=2
Однако я получаю java.lang.nullpointerexception Ошибка в следующей строке [/b] в тестировании моей службы (Registrationservice ). < /p>
redisTemplate.opsForHash().putAll(Key.toString(), (applicationData));
Подробнее здесь: https://stackoverflow.com/questions/502 ... redis-mock