You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Remko Popma <re...@gmail.com> on 2016/04/21 13:39:55 UTC

Adding JUnit tests for CsvParameterLayoutTest

I would like to re-run the CsvParameterlayoutTest
1. with its current configuration
2. with a configuration that uses <AsyncRoot> instead of <Root>
3. with all loggers asynchronous by setting system property
Log4jContextSelector to
org.apache.logging.log4j.core.async.AsyncLoggerContextSelector

I can just copy the test code and do the above in the setup, but I was
wondering if there is no way to parameterize the test to accomplish this?

Remko

Re: Adding JUnit tests for CsvParameterLayoutTest

Posted by Gary Gregory <ga...@gmail.com>.
Yes, thank you Kamal for pointing this out! JUnit's parameterized features
is *awesome*.

http://junit.sourceforge.net/javadoc/org/junit/runners/Parameterized.html


Gary

On Thu, Apr 21, 2016 at 6:12 AM, Kamal Mettananda <lk...@gmail.com> wrote:

> Hi Remko
>
> I am still new here, but thought of giving some input from a Junit
> parameterization point of view.
>
> It seems we can parameterize the ConfigurationFactory of
> CsvParameterLayoutTest using something like below to provide two
> Configurations as parameters.
>
> @RunWith(value = Parameterized.class)
> public class CsvParameterLayoutTest {
>
>     ConfigurationFactory cf = null;
>
>     public CsvParameterLayoutTest(ConfigurationFactory newcf) {
>         cf = newcf;
>         setupClass();
>     }
>
>     @Parameterized.Parameters(name = "{index}: configuration factory =
> {0}")
>     public static Iterable<Object[]> data1() {
>         return Arrays.asList(new Object[][] {
>                 {
>                         new BasicConfigurationFactory()
>                 },
>                 {
>                         new AsyncBasicConfigurationFactory()
>                 }
>         });
>     }
>
>    //@BeforeClass
>     public static void setupClass() {
>         ThreadContext.clearAll();
>         ConfigurationFactory.setConfigurationFactory(cf);
>         System.out.println("================ " + cf.getClass().getName());
>         final LoggerContext ctx = LoggerContext.getContext();
>         ctx.reconfigure();
>     }
>
>     ....
> }
>
> Hope this will help.
>
> Thanks
>
> ---------------------------------------
> Kamal Mettananda
> www.digizol.com
>
>
> On Thu, Apr 21, 2016 at 5:09 PM, Remko Popma <re...@gmail.com>
> wrote:
>
>> I would like to re-run the CsvParameterlayoutTest
>> 1. with its current configuration
>> 2. with a configuration that uses <AsyncRoot> instead of <Root>
>> 3. with all loggers asynchronous by setting system property
>> Log4jContextSelector to
>> org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
>>
>> I can just copy the test code and do the above in the setup, but I was
>> wondering if there is no way to parameterize the test to accomplish this?
>>
>> Remko
>>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: Adding JUnit tests for CsvParameterLayoutTest

Posted by Kamal Mettananda <lk...@gmail.com>.
Hi Remko

I am still new here, but thought of giving some input from a Junit
parameterization point of view.

It seems we can parameterize the ConfigurationFactory of
CsvParameterLayoutTest using something like below to provide two
Configurations as parameters.

@RunWith(value = Parameterized.class)
public class CsvParameterLayoutTest {

    ConfigurationFactory cf = null;

    public CsvParameterLayoutTest(ConfigurationFactory newcf) {
        cf = newcf;
        setupClass();
    }

    @Parameterized.Parameters(name = "{index}: configuration factory = {0}")
    public static Iterable<Object[]> data1() {
        return Arrays.asList(new Object[][] {
                {
                        new BasicConfigurationFactory()
                },
                {
                        new AsyncBasicConfigurationFactory()
                }
        });
    }

   //@BeforeClass
    public static void setupClass() {
        ThreadContext.clearAll();
        ConfigurationFactory.setConfigurationFactory(cf);
        System.out.println("================ " + cf.getClass().getName());
        final LoggerContext ctx = LoggerContext.getContext();
        ctx.reconfigure();
    }

    ....
}

Hope this will help.

Thanks

---------------------------------------
Kamal Mettananda
www.digizol.com


On Thu, Apr 21, 2016 at 5:09 PM, Remko Popma <re...@gmail.com> wrote:

> I would like to re-run the CsvParameterlayoutTest
> 1. with its current configuration
> 2. with a configuration that uses <AsyncRoot> instead of <Root>
> 3. with all loggers asynchronous by setting system property
> Log4jContextSelector to
> org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
>
> I can just copy the test code and do the above in the setup, but I was
> wondering if there is no way to parameterize the test to accomplish this?
>
> Remko
>