首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NoSQLUnit MongoDB插入集合名为[]

NoSQLUnit MongoDB插入集合名为[]
EN

Stack Overflow用户
提问于 2015-04-14 06:45:47
回答 1查看 435关注 0票数 1

我试图在Spring项目中为类编写一个JUnit测试用例。但我一直有例外。

com.lordofthejars.nosqlunit.core.NoSqlAssertionError:预期的集合名是学生,但是插入集合名是[]

有什么建议吗?非常感谢!

代码语言:javascript
复制
@Configuration
@EnableMongoRepositories
@ComponentScan("com.tp.repository")
public class TestConfig extends AbstractMongoConfiguration {

    @Bean
    public Mongo mongo() {
        return new Fongo("Fongo").getMongo();
    }

    @Bean
    protected String getDatabaseName() {
        return "test";
    }

}

单元测试类

代码语言:javascript
复制
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = TestConfig.class)
public class StudentRepositoryTests {

    @Autowired
    StudentRepository studentRepository;

    @Autowired
    private ApplicationContext applicationContext;

    @Rule
    public MongoDbRule mongoDbRule = MongoDbRuleBuilder.newMongoDbRule()
            .defaultSpringMongoDb("student");

    @Test
    @ShouldMatchDataSet(location = "/student.json")
    public void shouldSave() {
        studentRepository.save(createStudent());
    }

    private Student createStudent() {
        Student student = new Student();
        student.setFirstName("First");
        student.setLastName("Last");
        return student;
    }

}

学生班

代码语言:javascript
复制
@Document(collection="student")
public class Student {

    @Id
    private String id;

    @Indexed
    private String firstName;

    @Indexed
    private String lastName;

    ....
}
EN

回答 1

Stack Overflow用户

发布于 2015-04-15 07:31:29

是的,理论上应该有效,但出于某种原因,我不知道为什么它不起作用。诚然,我的示例和测试使用的是xml方法,而不是配置方法,但在这两种情况下都应该有效。似乎有两个Fongo实例,其中一个用于插入数据,另一个用于检查数据。您能在github帐户中提供代码吗?这样我就可以调试并查看发生了什么?

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

https://stackoverflow.com/questions/29620819

复制
相关文章

相似问题

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