Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

EclipseLink/Development/Testing/StrawManProposal

< EclipseLink‎ | Development‎ | Testing
Revision as of 14:26, 4 December 2007 by Michael.norman.oracle.com (Talk | contribs) (New Testing Framework)

From the EclipseLink DevMeeting 071017, create a straw-man proposal for a new consolidated testing framework

New Testing Framework

  • based on JUnit4 - Why?
    • JUnit3 is at end-of-life
    • Eclipse IDE has built-in support for JUnit4 tests
    • while various testing frameworks have been extended, JUnit4 is extensible by design

Info on JUnit4

Info on JUnit4

Looking at requirements from MOXy/SDO/DBWS/JPA, this is what we've got so far ...

The Hollywood Principle

Don't call us, we'll call you The basic idea is to de-couple the tests from their resource setup requirements that currently are handled through Java inheritance (not the best for component re-use). The NTF instead injects the resource into a tagged context variable owned by the test. Setup for the context is done in a separate class with its own requirements for composition/aggregation/inheritance.

// javase imports
import java.util.Properties;

// JUnit imports
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

// ntf imports
import org.eclipse.persistence.ntf.TestContext;
import org.eclipse.persistence.ntf.TestContextRunner;
import org.eclipse.persistence.ntf.TestProperties;
import org.eclipse.persistence.ntf.Context;

@RunWith(TestContextRunner.class)
public class ASetOfSimpleTests {

    @TestProperties public static Properties properties;
    @TestContext(tag="context") public static Context<Object> context;

There are two things injected by the TestContextRunner:

1. Properties

  • found in the ntf.xml file in the user's home directory:
 <?xml version="1.0" encoding="UTF-8"?> 
 <ntf>
   <properties>
     <property
       name="easy_as">pie</property>
   </properties>

the name and location of the ntf.xml file can be altered by the Java System properties -Dntf.file=some_other_file.name and -Dntf.dir=some/directory/path

  • Java System properties

2. User-defined context object

  • an external factory constructs an object that implements Context, providing a simple API to look up objects by name:
public interface Context<V> {

    public boolean containsObject(String objectName);

    public V getObject(String objectName);

}

The rest of the ntf.xml document describes the factories used to build the Context objects:


    <test
      class="org.eclipse.persistence.ntf.junittests.ASetOfSimpleTests"
      >
      <context
        tag="context" 
        class="org.eclipse.persistence.ntf.junittests.SimpleContext">barf</context>
      <context
        tag="context2" 
        class="org.eclipse.persistence.ntf.junittests.DocumentContext">c:/temp/foo.xml</context>
    </test>

An example set of tests:

package org.eclipse.persistence.ntf.junittests;

// javase imports
import java.util.Properties;
import org.w3c.dom.Document;

// JUnit imports
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

// ntf imports
import org.eclipse.persistence.ntf.TestContext;
import org.eclipse.persistence.ntf.TestContextRunner;
import org.eclipse.persistence.ntf.TestProperties;
import org.eclipse.persistence.ntf.Context;
import org.eclipse.persistence.ntf.TestGroups;
import static org.eclipse.persistence.ntf.IgnoreAssertion.ignore;

@RunWith(TestContextRunner.class)
@TestGroups({"FirstGroup", "SecondGroup"})
public class ASetOfSimpleTests {

    @TestProperties public static Properties properties;
    @TestContext(tag="context") public static Context<Object> context;
    @TestContext(tag="context2") public static Context<Document> context2;

    @BeforeClass 
    public static void setUp() {
        System.identityHashCode(System.out);
    }
    
    @Before
    public void something() {
        System.identityHashCode(System.out);
    }
    
    @Test
    public void aSimpleTest() {
        assertTrue("no key 'java.version'", properties.containsKey("java.version"));
        assertNotNull("object @ 'some_key' is null", context.getObject("some_key"));
        assertTrue("object @ 'controlDocument' is not a org.w3c.dom.Document",
            context2.getObject("controlDocument") instanceof Document);
    }
    
    @Test
    public void anotherSimpleTest() {
        ignore("whatever!", true == true);
    }
    
    @Ignore
    public void yetAnotherSimpleTest() {
        assertFalse("whatever!", properties.containsKey("java.version"));
        
    }
}

Back to the top