首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Spring Boot中使用嵌入式Cassandra进行单元测试

在Spring Boot中使用嵌入式Cassandra进行单元测试
EN

Stack Overflow用户
提问于 2018-11-27 23:40:15
回答 1查看 2.1K关注 0票数 0

我正在尝试测试一个Spring Boot应用程序,其中包括保存到cassandra DB中。对于单元测试,我使用了EmbeddedCassandra。

这些是依赖项。

代码语言:javascript
复制
compile group: "com.datastax.cassandra", name: "cassandra-driver-core", version:"2.1.7"
    compile group: "com.datastax.cassandra", name: "cassandra-driver-dse", version:"2.1.7"
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile  ("org.cassandraunit:cassandra-unit-spring:2.1.9.2"){
        exclude group:"org.cassandraunit",module:"cassandra-unit"
    }

这些是我用过的注解

代码语言:javascript
复制
@RunWith(SpringRunner.class)
@WebMvcTest(value = MyController.class)
@Import(value = {MyDao.class})
@ContextConfiguration
@TestExecutionListeners(listeners = {
        CassandraUnitDependencyInjectionTestExecutionListener.class,
        CassandraUnitTestExecutionListener.class,
        ServletTestExecutionListener.class,
        DependencyInjectionTestExecutionListener.class,
        DirtiesContextTestExecutionListener.class}
)
@EmbeddedCassandra(timeout = 60000)
@CassandraDataSet(keyspace = "test", value = {"test.cql"})

但是在单元测试中保存的值是填充原始cassandra数据库的。有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2018-12-02 05:19:00

Cassandra单元使用: native_transport_port: 9142,但是spring boot需要9042端口,所以您应该在配置中更改端口或使用cassandra.yaml文件。作为另一种选择,你可以看看这个:

https://github.com/nosan/embedded-cassandra/blob/master/README.adoc#spring-boot

它还提供@Cql注释,以便在每次测试之前或/和之后执行cql脚本。

希望,这会对你有用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53503146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档