[hibernate-dev] [Hibernate Search] Added a test utility to assert produced log
Hi team, Just so you know, if you ever need to assert that a certain log is produced in your JUnit tests, there's now a tool to do just that in Hibernate Search: org.hibernate.search.test.util.impl.ExpectedLog4jLog [1] You may use it much like you would use the ExpectedException rule: public class MyTest { @org.junit.Rule public ExpectedLog4jLog logged = ExpectedLog4jLog.create(); @Test public void test() { logged.expectMessage( "HSEARCH400032", "some substring I want in the same log" ); // ... Do test ... } } You can also assert more complex conditions on the logs, using a org.hamcrest.Matcher, but then it's starting to get a bit exotic. You may find an example of real-life use at [2]. [1] https://github.com/hibernate/hibernate-search/blob/master/engine/src/test/java/org/hibernate/search/test/util/impl/ExpectedLog4jLog.java [2] https://github.com/hibernate/hibernate-search/blob/master/elasticsearch/src/test/java/org/hibernate/search/elasticsearch/test/ElasticsearchUnsupportedFeaturesIT.java Cheers, Yoann Rodière Hibernate NoORM Team ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] [Hibernate Search] Added a test utility to assert produced log
Nice trick! I didn't know about the Log4j feature, but had created something similar for JBoss Logging; it's in the ORM project though so not easily reusable in all of Search components: - org.hibernate.testing.logger.LoggerInspectionRule On 4 November 2016 at 13:41, Yoann Rodiere wrote: > Hi team, > > Just so you know, if you ever need to assert that a certain log is produced > in your JUnit tests, there's now a tool to do just that in Hibernate > Search: org.hibernate.search.test.util.impl.ExpectedLog4jLog [1] > > You may use it much like you would use the ExpectedException rule: > > public class MyTest { > @org.junit.Rule > public ExpectedLog4jLog logged = ExpectedLog4jLog.create(); > > @Test > public void test() { > logged.expectMessage( "HSEARCH400032", "some substring I want in the same > log" ); > > // ... Do test ... > } > } > > You can also assert more complex conditions on the logs, using > a org.hamcrest.Matcher, but then it's starting to > get a bit exotic. > > You may find an example of real-life use at [2]. > > [1] > https://github.com/hibernate/hibernate-search/blob/master/engine/src/test/java/org/hibernate/search/test/util/impl/ExpectedLog4jLog.java > [2] > https://github.com/hibernate/hibernate-search/blob/master/elasticsearch/src/test/java/org/hibernate/search/elasticsearch/test/ElasticsearchUnsupportedFeaturesIT.java > > Cheers, > > Yoann Rodière > Hibernate NoORM Team > ___ > hibernate-dev mailing list > hibernate-dev@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/hibernate-dev ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] [Hibernate Search] Added a test utility to assert produced log
I think we should consider creating a set of generic testing utils as a separate project. Things like LoggerInspectionRule, @ExpectedFailure, @BeforeClassOnce, @AfterClassOnce, @Skip, etc are generally useful I find On Fri, Nov 4, 2016 at 9:16 AM Sanne Grinovero wrote: > Nice trick! > > I didn't know about the Log4j feature, but had created something > similar for JBoss Logging; it's in the ORM project though so not > easily reusable in all of Search components: > - org.hibernate.testing.logger.LoggerInspectionRule > > On 4 November 2016 at 13:41, Yoann Rodiere wrote: > > Hi team, > > > > Just so you know, if you ever need to assert that a certain log is > produced > > in your JUnit tests, there's now a tool to do just that in Hibernate > > Search: org.hibernate.search.test.util.impl.ExpectedLog4jLog [1] > > > > You may use it much like you would use the ExpectedException rule: > > > > public class MyTest { > > @org.junit.Rule > > public ExpectedLog4jLog logged = ExpectedLog4jLog.create(); > > > > @Test > > public void test() { > > logged.expectMessage( "HSEARCH400032", "some substring I want in the same > > log" ); > > > > // ... Do test ... > > } > > } > > > > You can also assert more complex conditions on the logs, using > > a org.hamcrest.Matcher, but then it's starting to > > get a bit exotic. > > > > You may find an example of real-life use at [2]. > > > > [1] > > > https://github.com/hibernate/hibernate-search/blob/master/engine/src/test/java/org/hibernate/search/test/util/impl/ExpectedLog4jLog.java > > [2] > > > https://github.com/hibernate/hibernate-search/blob/master/elasticsearch/src/test/java/org/hibernate/search/elasticsearch/test/ElasticsearchUnsupportedFeaturesIT.java > > > > Cheers, > > > > Yoann Rodière > > Hibernate NoORM Team > > ___ > > hibernate-dev mailing list > > hibernate-dev@lists.jboss.org > > https://lists.jboss.org/mailman/listinfo/hibernate-dev > > ___ > hibernate-dev mailing list > hibernate-dev@lists.jboss.org > https://lists.jboss.org/mailman/listinfo/hibernate-dev ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] [Hibernate Search] Added a test utility to assert produced log
On 4 November 2016 at 14:27, Steve Ebersole wrote: > I think we should consider creating a set of generic testing utils as a > separate project. Things like LoggerInspectionRule, @ExpectedFailure, > @BeforeClassOnce, @AfterClassOnce, @Skip, etc are generally useful I find +1 for the general testing utilities, however the LoggerInspectionRule will move into a JBoss Logger utility as it's useful for anyone using JBoss Logger. > On Fri, Nov 4, 2016 at 9:16 AM Sanne Grinovero wrote: >> >> Nice trick! >> >> I didn't know about the Log4j feature, but had created something >> similar for JBoss Logging; it's in the ORM project though so not >> easily reusable in all of Search components: >> - org.hibernate.testing.logger.LoggerInspectionRule >> >> On 4 November 2016 at 13:41, Yoann Rodiere wrote: >> > Hi team, >> > >> > Just so you know, if you ever need to assert that a certain log is >> > produced >> > in your JUnit tests, there's now a tool to do just that in Hibernate >> > Search: org.hibernate.search.test.util.impl.ExpectedLog4jLog [1] >> > >> > You may use it much like you would use the ExpectedException rule: >> > >> > public class MyTest { >> > @org.junit.Rule >> > public ExpectedLog4jLog logged = ExpectedLog4jLog.create(); >> > >> > @Test >> > public void test() { >> > logged.expectMessage( "HSEARCH400032", "some substring I want in the >> > same >> > log" ); >> > >> > // ... Do test ... >> > } >> > } >> > >> > You can also assert more complex conditions on the logs, using >> > a org.hamcrest.Matcher, but then it's starting >> > to >> > get a bit exotic. >> > >> > You may find an example of real-life use at [2]. >> > >> > [1] >> > >> > https://github.com/hibernate/hibernate-search/blob/master/engine/src/test/java/org/hibernate/search/test/util/impl/ExpectedLog4jLog.java >> > [2] >> > >> > https://github.com/hibernate/hibernate-search/blob/master/elasticsearch/src/test/java/org/hibernate/search/elasticsearch/test/ElasticsearchUnsupportedFeaturesIT.java >> > >> > Cheers, >> > >> > Yoann Rodière >> > Hibernate NoORM Team >> > ___ >> > hibernate-dev mailing list >> > hibernate-dev@lists.jboss.org >> > https://lists.jboss.org/mailman/listinfo/hibernate-dev >> >> ___ >> hibernate-dev mailing list >> hibernate-dev@lists.jboss.org >> https://lists.jboss.org/mailman/listinfo/hibernate-dev ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev
Re: [hibernate-dev] [Hibernate Search] Added a test utility to assert produced log
Sweet. Good to know On Fri, Nov 4, 2016 at 9:30 AM Sanne Grinovero wrote: > On 4 November 2016 at 14:27, Steve Ebersole wrote: > > I think we should consider creating a set of generic testing utils as a > > separate project. Things like LoggerInspectionRule, @ExpectedFailure, > > @BeforeClassOnce, @AfterClassOnce, @Skip, etc are generally useful I find > > +1 for the general testing utilities, however the LoggerInspectionRule > will move into a JBoss Logger utility as it's useful for anyone using > JBoss Logger. > > > > On Fri, Nov 4, 2016 at 9:16 AM Sanne Grinovero > wrote: > >> > >> Nice trick! > >> > >> I didn't know about the Log4j feature, but had created something > >> similar for JBoss Logging; it's in the ORM project though so not > >> easily reusable in all of Search components: > >> - org.hibernate.testing.logger.LoggerInspectionRule > >> > >> On 4 November 2016 at 13:41, Yoann Rodiere wrote: > >> > Hi team, > >> > > >> > Just so you know, if you ever need to assert that a certain log is > >> > produced > >> > in your JUnit tests, there's now a tool to do just that in Hibernate > >> > Search: org.hibernate.search.test.util.impl.ExpectedLog4jLog [1] > >> > > >> > You may use it much like you would use the ExpectedException rule: > >> > > >> > public class MyTest { > >> > @org.junit.Rule > >> > public ExpectedLog4jLog logged = ExpectedLog4jLog.create(); > >> > > >> > @Test > >> > public void test() { > >> > logged.expectMessage( "HSEARCH400032", "some substring I want in the > >> > same > >> > log" ); > >> > > >> > // ... Do test ... > >> > } > >> > } > >> > > >> > You can also assert more complex conditions on the logs, using > >> > a org.hamcrest.Matcher, but then it's starting > >> > to > >> > get a bit exotic. > >> > > >> > You may find an example of real-life use at [2]. > >> > > >> > [1] > >> > > >> > > https://github.com/hibernate/hibernate-search/blob/master/engine/src/test/java/org/hibernate/search/test/util/impl/ExpectedLog4jLog.java > >> > [2] > >> > > >> > > https://github.com/hibernate/hibernate-search/blob/master/elasticsearch/src/test/java/org/hibernate/search/elasticsearch/test/ElasticsearchUnsupportedFeaturesIT.java > >> > > >> > Cheers, > >> > > >> > Yoann Rodière > >> > Hibernate NoORM Team > >> > ___ > >> > hibernate-dev mailing list > >> > hibernate-dev@lists.jboss.org > >> > https://lists.jboss.org/mailman/listinfo/hibernate-dev > >> > >> ___ > >> hibernate-dev mailing list > >> hibernate-dev@lists.jboss.org > >> https://lists.jboss.org/mailman/listinfo/hibernate-dev > ___ hibernate-dev mailing list hibernate-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/hibernate-dev