You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Héctor A <ne...@gmail.com> on 2015/08/26 10:51:14 UTC

FlexUnit doubt

Hi guys,

  I have a series of test classes, and a lot of them require me to first
run a piece of code, that is also being tested on a different test class.
I'm not a FlexUnit expert, so I'm wondering if there's some way of forcing
that piece of code to be tested first even if I run some test class/method
individually, and then take the result from that test for the one that's
actually being tested, and, of course, only run the initial test once.

  Can this be achieved with BeforeClass/AfterClass or rules? I´m browsing
the documentation, but it´s always nicer to hear from other people, their
experiences, etc.

Thanks for your help.

Re: FlexUnit doubt

Posted by Héctor A <ne...@gmail.com>.
I'm fully aware of what you say. And you are right, these ones are not unit
tests, I didn't mention the word on purpose. I always strive for unit
tests, but in this case they need to be integration tests and have to hit
many external resources. It also allowed to find bugs in those external
resources.

I'm also using mockolate, not as powerful as i'd like, but it's also the
fault of not having better reflection, proxies, etc I guess.

2015年8月30日日曜日、Justin Mclean<ju...@classsoftware.com>さんは書きました:

> Hi,
>
> > I know about test suites, but it's not exactly what I'm looking for, I'm
> > talking about reusing logic in several tests
>
> Sounds to me like your tests are more integration test than unit tests. If
> you’ve not read "Working Effectively with Legacy Code” by Michael Feathers
> you might want to take a look.
>
> In it he says "A unit test that takes 1/10th of a second to run is a slow
> unit test.” so any test that touches a database or makes a HTTP call is
> probably not a unit test. That being said it's better to have tests than no
> tests at all. I’d try an aim for a 80% / 20% rule re integration vs unit
> test.
>
> Also look into Mocks they will make you’re life easier and your tests
> faster.
>
> Thanks,
> Justin
>

Re: FlexUnit doubt

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

> I know about test suites, but it's not exactly what I'm looking for, I'm
> talking about reusing logic in several tests

Sounds to me like your tests are more integration test than unit tests. If you’ve not read "Working Effectively with Legacy Code” by Michael Feathers you might want to take a look.

In it he says "A unit test that takes 1/10th of a second to run is a slow unit test.” so any test that touches a database or makes a HTTP call is probably not a unit test. That being said it's better to have tests than no tests at all. I’d try an aim for a 80% / 20% rule re integration vs unit test.

Also look into Mocks they will make you’re life easier and your tests faster.

Thanks,
Justin

Re: FlexUnit doubt

Posted by Héctor A <ne...@gmail.com>.
I didn't think of that idea, what I did in the end was to create a custom
Rule. Not exactly what I was looking for in the beginning, but it allowed
me to create a rather flexible, customizable a reusable piece of logic.

On Thu, Aug 27, 2015 at 11:31 PM, Justin Ransom Dallas <
justindallas@gmail.com> wrote:

> Your tests can extend a base class which can contain highly reused code.
> The biggest issue is going to be your async setup code,  and making sure
> that subclasses of the parent test wait for the superclass.   I've got some
> code that does that,  I just have to find it.
>
> On Wednesday, August 26, 2015, Héctor A <ne...@gmail.com> wrote:
>
> > I know about test suites, but it's not exactly what I'm looking for, I'm
> > talking about reusing logic in several tests, also allowing them to be
> run
> > "individually" (at least in an automatized way) at any time, think of
> > setting up and connecting to a database, several tests use it, and you
> > don't want to do it for all of them, but there is also a test to check
> that
> > the logic used for connection is working properly (well, in this case
> it's
> > more complicated than that). Would be nice to get the connection from the
> > connection test and reuse it for the other tests.
> >
> > Maybe not running the test itself, but move part of the logic to another
> > class that can be shared between multiple tests could be nice as well, I
> > guess in this case we'd use a BeforeClass statement, but I'm not really
> > sure as in my case it's an asynchronous operation, I'll have to check the
> > documentation.
> >
> >
> >
> > On Wed, Aug 26, 2015 at 11:23 AM, Justin Mclean <
> justin@classsoftware.com
> > <javascript:;>>
> > wrote:
> >
> > > Hi,
> > >
> > > While the order of the tests are not specified within a single test
> > class,
> > > you can have multiple tests classes in a test suite and run those. I
> > think
> > > that does what you are asking. [1] It’s also possible with ant. [2] It
> > may
> > > be that Mocks (e.g. [3]) would also help you.
> > >
> > > Thanks,
> > > Justin
> > >
> > > 1. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite
> <
> > > https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite>
> > > 2. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task
> <
> > > https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task>
> > > 3. https://github.com/drewbourne/mockolate
> >
>
>
> --
> Justin Dallas
> Phone:814-880-5637
>

Re: FlexUnit doubt

Posted by Justin Ransom Dallas <ju...@gmail.com>.
Your tests can extend a base class which can contain highly reused code.
The biggest issue is going to be your async setup code,  and making sure
that subclasses of the parent test wait for the superclass.   I've got some
code that does that,  I just have to find it.

On Wednesday, August 26, 2015, Héctor A <ne...@gmail.com> wrote:

> I know about test suites, but it's not exactly what I'm looking for, I'm
> talking about reusing logic in several tests, also allowing them to be run
> "individually" (at least in an automatized way) at any time, think of
> setting up and connecting to a database, several tests use it, and you
> don't want to do it for all of them, but there is also a test to check that
> the logic used for connection is working properly (well, in this case it's
> more complicated than that). Would be nice to get the connection from the
> connection test and reuse it for the other tests.
>
> Maybe not running the test itself, but move part of the logic to another
> class that can be shared between multiple tests could be nice as well, I
> guess in this case we'd use a BeforeClass statement, but I'm not really
> sure as in my case it's an asynchronous operation, I'll have to check the
> documentation.
>
>
>
> On Wed, Aug 26, 2015 at 11:23 AM, Justin Mclean <justin@classsoftware.com
> <javascript:;>>
> wrote:
>
> > Hi,
> >
> > While the order of the tests are not specified within a single test
> class,
> > you can have multiple tests classes in a test suite and run those. I
> think
> > that does what you are asking. [1] It’s also possible with ant. [2] It
> may
> > be that Mocks (e.g. [3]) would also help you.
> >
> > Thanks,
> > Justin
> >
> > 1. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite <
> > https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite>
> > 2. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task <
> > https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task>
> > 3. https://github.com/drewbourne/mockolate
>


-- 
Justin Dallas
Phone:814-880-5637

Re: FlexUnit doubt

Posted by Héctor A <ne...@gmail.com>.
I know about test suites, but it's not exactly what I'm looking for, I'm
talking about reusing logic in several tests, also allowing them to be run
"individually" (at least in an automatized way) at any time, think of
setting up and connecting to a database, several tests use it, and you
don't want to do it for all of them, but there is also a test to check that
the logic used for connection is working properly (well, in this case it's
more complicated than that). Would be nice to get the connection from the
connection test and reuse it for the other tests.

Maybe not running the test itself, but move part of the logic to another
class that can be shared between multiple tests could be nice as well, I
guess in this case we'd use a BeforeClass statement, but I'm not really
sure as in my case it's an asynchronous operation, I'll have to check the
documentation.



On Wed, Aug 26, 2015 at 11:23 AM, Justin Mclean <ju...@classsoftware.com>
wrote:

> Hi,
>
> While the order of the tests are not specified within a single test class,
> you can have multiple tests classes in a test suite and run those. I think
> that does what you are asking. [1] It’s also possible with ant. [2] It may
> be that Mocks (e.g. [3]) would also help you.
>
> Thanks,
> Justin
>
> 1. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite <
> https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite>
> 2. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task <
> https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task>
> 3. https://github.com/drewbourne/mockolate

Re: FlexUnit doubt

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

While the order of the tests are not specified within a single test class, you can have multiple tests classes in a test suite and run those. I think that does what you are asking. [1] It’s also possible with ant. [2] It may be that Mocks (e.g. [3]) would also help you.

Thanks,
Justin

1. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite <https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+TestSuite>
2. https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task <https://cwiki.apache.org/confluence/display/FLEX/FlexUnit+Ant+Task>
3. https://github.com/drewbourne/mockolate