Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
452 views
in Technique[技术] by (71.8m points)

jdbc - Micronaut-Data JDBC-用于测试和生产的多种方言(Micronaut-Data JDBC - Multiple Dialects for Test and Production)

The Mirconaut docs on JDBC repositories clearly tells us we have to create a test repository to test against another dialect.

(JDBC存储库上的Mirconaut文档清楚地告诉我们,我们必须创建一个测试存储库以针对另一种方言进行测试。)

I think this will be manageable (eg Postgres for production and H2 for test).

(我认为这将是可管理的(例如,用于生产的Postgres和用于测试的H2)。)

The problem is I have to repeat my methods (eg find()) in the test repository.

(问题是我必须在测试存储库中重复我的方法(例如find())。)

I have a book repository and a test repository:

(我有一个书库和一个测试库:)

@JdbcRepository(dialect = Dialect.POSTGRES)
interface BookRepository extends CrudRepository<Book, Long> {
  Optional<Book> find(String title);
}

@JdbcRepository(dialect = Dialect.H2)
@Replaces(bean = BookRepository)
@Requires(env = ["test"])
interface TestBookRepository extends BookRepository {
  // Optional<Book> find(String title);
  // Required to make the find() method appear in the TestBookRepository
}

To make the find() method available in the TestBookRepository, I had to repeat the method (see commented line above).

(为了使find()方法在TestBookRepository中可用,我不得不重复该方法(请参见上面的注释行)。)

Is there a better way to avoid repeating myself?

(有更好的方法避免重复自己吗?)

The methods from the CrudRepository interface are available in the TestBookRepository without problems.

(TestBookRepository中提供了CrudRepository接口中的方法,没有问题。)

Why is the find() method not treated the same?

(为什么find()方法不一样?)

BTW, I don't want to mock the test repository.

(顺便说一句,我不想??模拟测试库。)

I want to test the repository 'logic' injected by Micronaut-Data against an SQL database.

(我想针对SQL数据库测试Micronaut-Data注入的存储库“逻辑”。)

  ask by Mike Houston translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...