我有一个使用spring-data-cassandra的spring boot应用程序。我正在尝试使用嵌入式Cassandra编写此应用程序的集成测试。
这是我使用的依赖项:
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'junit'
}
testCompile("org.junit.jupiter:junit-jupiter-api:5.3.2")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.3.2")
testCompile("org.mockito:mockito-junit-jupiter:2.23.4")
testCompile group: 'org.cassandraunit', name: 'cassandra-unit-spring', version: '3.5.0.1'
这是测试代码:
import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.CassandraUnitTestExecutionListener;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@ContextConfiguration
@TestExecutionListeners(
listeners = CassandraUnitTestExecutionListener.class,
mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
@CassandraDataSet(value = "dataset.cql", keyspace = "key_space")
@EmbeddedCassandra
@ActiveProfiles("test")
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class IntegrationTest {
@Test
public void test() {
System.out.println("Test");
}
}
但是,当我运行该应用程序时,出现以下错误:
com.datastax.driver.core.exceptions.NoHostAvailableException
这意味着默认的Cassandra嵌入式配置不起作用!
答案 0 :(得分:0)