You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by David Blevins <da...@visi.com> on 2009/09/29 03:33:10 UTC

Re: JUnit Runner 0.1

On Sep 27, 2009, at 12:16 PM, Quintin Beukes wrote:

> Hey,
>
> The previous runner I started modifying extensively to customize for
> our company's tests. I already had a small testing framework for the
> tests, which used Spring to initial OpenEJB and do the lookups. I
> changed this to use the runner technique.
>
> Then over the weekend I decided to extract the runner code into an
> openejb-junit project, and make it extensible so I could use the
> library's code and only extend to give our tests the same
> functionality.
>
> This is what I came up with: https://issues.apache.org/jira/browse/OPENEJB-1078
>
> The JUnit tests demonstrate it's behaviour. These 3 tests are the  
> best examples:
> org.apache.openejb.junit.TestEjbBasic
> org.apache.openejb.junit.TestEjbSecurity
> org.apache.openejb.junit.TestDualConfigOverride
>
> It supports class level configuration of the InitialContext, and then
> method specific configurations. You can configure the InitialContext
> from a file, or by directly specifying properties. You can have
> OpenEJB do any of it's supported injections, or you can have the
> runner inject the InitialContext (or it's initialization Properties
> object) and do your own lookups. You can specify as which role to load
> the InitialContext (basically a RunAs).
>
> I'm planning on doing resource configurations, such as datasources.
> Any other suggestions, please throw them my way. And please send me
> feedback. So far it's working very well for my tests. I have yet to
> complete the spring modification, but for those tests which don't
> require it, it works very well. Especially the role tests.
>
> Not that it still doesn't support JUnit 3. If you require JUnit 3, let
> me know and I'll prioritize implementing JUnit 3 support.
>
> An basic example would be the following:
> @RunWith(OpenEjbRunner.class)
> @ContextConfig(
>  properties={
>     
> @Property 
> ("java 
> .naming 
> .factory 
> .initial=org.apache.openejb.client.LocalInitialContextFactory")
>  }
> )
> @LocalClient
> public class TestEjbSecurity
> {
>  @EJB
>  private MyBusinessBean myBean;
>
>  @TestResource
>  private InitialContext currentInitialContext;
>
>  @Test
>  @ContextConfig(
>    securityRole="Admin"
>  )
>  public void testAsAdmin()
>  {
>    myBean.someMethod();
>    currentInitialContext.lookup("some/custom/lookup");
>  }
>
>  @Test
>  @ContextConfig(
>    propertiesFile="/META-INF/employee-context.properties",
>    securityRole="Employe"
>  )
>  public void testAsEmployee()
>  {
>    myBean.someMethod();
>  }
> }

Looks like a great start.  For code of this size we'll definitely need  
a CLA on file - http://apache.org/licenses/#clas

Once we get that on file, we can check this into a branch and hammer  
on it together.  I've been itching to work on this feature for a bit  
as well, so this will be fun.  Have a bunch of ideas around  
transactions, rerunning tests, and some security stuff too.  Haven't  
had a chance to look too closely at the code you've got, but initial  
glance seems like it will be a good prototype.

Do you know if TestNG has a similar Test Runner concept?


-David





Re: JUnit Runner

Posted by Mohammad Nour El-Din <no...@gmail.com>.
+1 @ Jean-Louis

On Mon, Nov 15, 2010 at 9:29 AM, Jean-Louis MONTEIRO
<je...@atosorigin.com> wrote:
>
> Hi David,
>
> From the end user point of view (at least in my company), that would be
> great to consider a test case as a no-interface view bean or so.
>
> Basically, they need to be able to inject resources, EJBs, ... as if they
> were in a stateless for example.
> The point I mean is transactions!
> De we need to deal with transactions in TestCases? IMO, no!
>
> Either way, they need something simple to increase productivity.
> Quintin's proposal was AFAIC simple.
> Your testcase is also very useful but it targets advanced people if they
> want to build their own application/module, ... (very useful to build our
> testcases for example)
>
> I would be in favor of pushing something basic and simple and wait for some
> feedback of the community.
> IMHO, it's simpler to push something simple and enhance it afterwards, than
> pushing something more complex/feature-full and having to break something in
> next releases.
>
>
> Jean-Louis
> --
> View this message in context: http://openejb.979440.n4.nabble.com/Re-JUnit-Runner-0-1-tp988903p3042736.html
> Sent from the OpenEJB Dev mailing list archive at Nabble.com.
>



-- 
Thanks
- Mohammad Nour
  Author of (WebSphere Application Server Community Edition 2.0 User Guide)
  http://www.redbooks.ibm.com/abstracts/sg247585.html
- LinkedIn: http://www.linkedin.com/in/mnour
- Blog: http://tadabborat.blogspot.com
----
"Life is like riding a bicycle. To keep your balance you must keep moving"
- Albert Einstein

"Writing clean code is what you must do in order to call yourself a
professional. There is no reasonable excuse for doing anything less
than your best."
- Clean Code: A Handbook of Agile Software Craftsmanship

"Stay hungry, stay foolish."
- Steve Jobs

Re: JUnit Runner

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Hi David,

>From the end user point of view (at least in my company), that would be
great to consider a test case as a no-interface view bean or so.

Basically, they need to be able to inject resources, EJBs, ... as if they
were in a stateless for example.
The point I mean is transactions!
De we need to deal with transactions in TestCases? IMO, no!

Either way, they need something simple to increase productivity.
Quintin's proposal was AFAIC simple.
Your testcase is also very useful but it targets advanced people if they
want to build their own application/module, ... (very useful to build our
testcases for example)

I would be in favor of pushing something basic and simple and wait for some
feedback of the community.
IMHO, it's simpler to push something simple and enhance it afterwards, than
pushing something more complex/feature-full and having to break something in
next releases.


Jean-Louis
-- 
View this message in context: http://openejb.979440.n4.nabble.com/Re-JUnit-Runner-0-1-tp988903p3042736.html
Sent from the OpenEJB Dev mailing list archive at Nabble.com.

Re: JUnit Runner

Posted by David Blevins <da...@visi.com>.
On Feb 23, 2010, at 3:14 AM, David Blevins wrote:

> Hey Quintin!
> 
> Checked this little gem in -- sorry it's taken so long to get it reviewed.  There's some good stuff in here.  I was going to check it into a branch, but it's in pretty awesome shape.  Really gets the creative juices flowing.
> 
> We can support @RunTestAs using the same code the container uses to support @RunAs -- we could even use the same annotation.  No need for a special LoginModule  We could also add in support for @TransactionAttribute and even @Interceptors.  All of the above will be a little sneaky and take a bit of dancing, but totally doable.
> 
> First thing though is I think we should flatten out all the abstractions that aren't critical.  The security stuff for example strings from OpenEjbRunner to JUnit4Runner and through OpenEjbTestContext.  With this approach it's going to be real difficult to add more test method annotations.  Most this comes from trying to get away from direct JUnit 4 usage.  I think for this first iteration we can just make our lives simple, yank those abstractions and just code straight against JUnit4.  We'll probably end up with a third of the code.  So OpenEjbRunner and JUnit4Runner can get merged, TestContext can get yanked and everything can become a Statement.
> 
> What do you think?

Digging up this thread again.

Did some more tinkering with this kind of concept.  Check out:

  http://svn.apache.org/repos/asf/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateless/StatelessContainerTest.java

A cross between the stuff Quintin was working on and the validation test stuff that Karan did.  Takes the "build and return an app" concept from Karan's work and pulls it into the "test runner with injection" that Quintin prototyped.  The stuff that I hacked on is also not really ready for primetime as it doesn't do any scanning for apps in the classpath -- only the ability to build apps programmatically.  Ideally we'd have both ... either in different test runners or the same.

Tricky part obviously is that once we put something in front of users, we can't ever change it's behavior in any incompatible way.  All the stuff we have goes a bit too far into the experimental.

Wondering if doing a very stripped down version is the best approach to getting something out there and then float some of the ideas out in snapshots to get some feedback.

Thoughts?


-David



Re: JUnit Runner

Posted by David Blevins <da...@visi.com>.
Hey Quintin!

Checked this little gem in -- sorry it's taken so long to get it  
reviewed.  There's some good stuff in here.  I was going to check it  
into a branch, but it's in pretty awesome shape.  Really gets the  
creative juices flowing.

We can support @RunTestAs using the same code the container uses to  
support @RunAs -- we could even use the same annotation.  No need for  
a special LoginModule  We could also add in support for  
@TransactionAttribute and even @Interceptors.  All of the above will  
be a little sneaky and take a bit of dancing, but totally doable.

First thing though is I think we should flatten out all the  
abstractions that aren't critical.  The security stuff for example  
strings from OpenEjbRunner to JUnit4Runner and through  
OpenEjbTestContext.  With this approach it's going to be real  
difficult to add more test method annotations.  Most this comes from  
trying to get away from direct JUnit 4 usage.  I think for this first  
iteration we can just make our lives simple, yank those abstractions  
and just code straight against JUnit4.  We'll probably end up with a  
third of the code.  So OpenEjbRunner and JUnit4Runner can get merged,  
TestContext can get yanked and everything can become a Statement.

What do you think?

-David




Re: Re: JUnit Runner 0.1

Posted by Quintin Beukes <qu...@last.za.net>.
Re. this.

Is there anything you want changed on it? Any designs/features? I'm looking
for something to do over the weekend. I have to do a certain amount of
programming to keep my emotional level high :>

As you also probably noticed, I heavily commented it. I tried to explain
what everything does. It's a bit over the top, but the JUnit runner design
isn't very flexible if you want to keep to good OOP principals. A lot of
innovation and maturity will be needed to have it even close to as
modular/flexible as OpenEJB. So to accommodate for this I added many
comments to describe it.

It's not a very nice design. It works, though I keep feeling like it's a
mess, and wanting to rewrite it. Though, it's difficult to think of ways to
keep it modular and extensible without too much effort from the user into
using it.

Quintin Beukes


On Fri, Oct 30, 2009 at 10:08 PM, Quintin Beukes <qu...@last.za.net>wrote:

> Sorry, meant to send this to the list.
>
>
> ---------- Forwarded message ----------
> From: Quintin Beukes <qu...@last.za.net>
> Date: Fri, Oct 30, 2009 at 10:06 PM
> Subject: Re: JUnit Runner 0.1
> To: David Blevins <da...@visi.com>
>
>
> re. this.
>
> As you probably noticed the source formatting is very different from that
> of OpenEJB. Eclipse has a code formatter/cleanup feature. Feel free to run
> it and reformat the code according to OpenEJB standards.
>
> I'm not used to developing in other styles. Where ever I work the styles
> are usually decided by myself, so I'm used to a certain style. Whenever I
> work on Geronimo/OpenEJB code I keep having to reformat when I notice this.
> Having worked from a clean code base for the JUnit runner there wasn't any
> reminders. I actually only thought of it now when I jumped into the source
> code.
>
> Quintin Beukes
>
>
>

Fwd: Re: JUnit Runner 0.1

Posted by Quintin Beukes <qu...@last.za.net>.
Sorry, meant to send this to the list.


---------- Forwarded message ----------
From: Quintin Beukes <qu...@last.za.net>
Date: Fri, Oct 30, 2009 at 10:06 PM
Subject: Re: JUnit Runner 0.1
To: David Blevins <da...@visi.com>


re. this.

As you probably noticed the source formatting is very different from that of
OpenEJB. Eclipse has a code formatter/cleanup feature. Feel free to run it
and reformat the code according to OpenEJB standards.

I'm not used to developing in other styles. Where ever I work the styles are
usually decided by myself, so I'm used to a certain style. Whenever I work
on Geronimo/OpenEJB code I keep having to reformat when I notice this.
Having worked from a clean code base for the JUnit runner there wasn't any
reminders. I actually only thought of it now when I jumped into the source
code.

Quintin Beukes