Eunit testing after starting the application

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Eunit testing after starting the application

Code Wiget
Hey everyone,

How do you go about EUnit testing that requires the whole application to be running before the test ?

For example, my erlang application starts one pool of processes that connects to a database and another that connects to another server in our backend. To run any real tests, I’m going to need to have one or both of those systems up and running. The way that I’m doing is right now is below, and it is very cluge-y feeling:

ok = application:start(compiler),
ok = application:start(syntax_tools),
ok = application:start(goldrush),
ok = application:start(gproc),
ok = application:start(gen_logger),
ok = application:start(pooler),
ok = application:start(quickrand),
ok = application:start(re2),
ok = application:start(lz4),
ok = application:start(uuid),
ok = application:start(semver),
ok = application:start(snappy),
ok = application:start(cqerl),
ok = application:start(ecpool),
ok = application:start(esockd),
ok = application:start(lager_syslog),
ok = application:start(lager),


This system works because none of the above applications require any environment variables from a config file. So some of my other applications can’t run using this. Is there any way to have eunit run the test after starting the whole application? 

Thanks!



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Eunit testing after starting the application

Nathaniel Waisbrot
I don't have a good answer to your exact question, but I do have two tips: `application:ensure_all_started/1` asks Erlang to figure out how to start all the dependencies in the correct order and handles the case of an application already having been started.

And `application:set_env/4` will allow you to programmatically set the Erlang env variables without a config file.




On May 31, 2018, at 11:24 AM, Code Wiget <[hidden email]> wrote:

Hey everyone,

How do you go about EUnit testing that requires the whole application to be running before the test ?

For example, my erlang application starts one pool of processes that connects to a database and another that connects to another server in our backend. To run any real tests, I’m going to need to have one or both of those systems up and running. The way that I’m doing is right now is below, and it is very cluge-y feeling:

ok = application:start(compiler),
ok = application:start(syntax_tools),
ok = application:start(goldrush),
ok = application:start(gproc),
ok = application:start(gen_logger),
ok = application:start(pooler),
ok = application:start(quickrand),
ok = application:start(re2),
ok = application:start(lz4),
ok = application:start(uuid),
ok = application:start(semver),
ok = application:start(snappy),
ok = application:start(cqerl),
ok = application:start(ecpool),
ok = application:start(esockd),
ok = application:start(lager_syslog),
ok = application:start(lager),


This system works because none of the above applications require any environment variables from a config file. So some of my other applications can’t run using this. Is there any way to have eunit run the test after starting the whole application? 

Thanks!


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Eunit testing after starting the application

Gleb Vinogradov
In reply to this post by Code Wiget
You can use CommonTest to bootstrap your application. Set environment variables, start applications etc in CommonTest and run EUnit test then.

2018-05-31 22:24 GMT+07:00 Code Wiget <[hidden email]>:
Hey everyone,

How do you go about EUnit testing that requires the whole application to be running before the test ?

For example, my erlang application starts one pool of processes that connects to a database and another that connects to another server in our backend. To run any real tests, I’m going to need to have one or both of those systems up and running. The way that I’m doing is right now is below, and it is very cluge-y feeling:

ok = application:start(compiler),
ok = application:start(syntax_tools),
ok = application:start(goldrush),
ok = application:start(gproc),
ok = application:start(gen_logger),
ok = application:start(pooler),
ok = application:start(quickrand),
ok = application:start(re2),
ok = application:start(lz4),
ok = application:start(uuid),
ok = application:start(semver),
ok = application:start(snappy),
ok = application:start(cqerl),
ok = application:start(ecpool),
ok = application:start(esockd),
ok = application:start(lager_syslog),
ok = application:start(lager),


This system works because none of the above applications require any environment variables from a config file. So some of my other applications can’t run using this. Is there any way to have eunit run the test after starting the whole application? 

Thanks!



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Eunit testing after starting the application

Code Wiget
Nathaniel,

Thank you - ensure_all_started is going to save me dozens of lines of code in other locations =).

Gleb,

Are you suggesting not doing eunit testing and just running with common tests and using init_per_testcase ? I get that EUnit is easy, but for an application that is already built, when we are trying to test system functionality, maybe it is better to just go full on with the common test suite?



On May 31, 2018, 11:42 AM -0400, Gleb Vinogradov <[hidden email]>, wrote:
You can use CommonTest to bootstrap your application. Set environment variables, start applications etc in CommonTest and run EUnit test then.

2018-05-31 22:24 GMT+07:00 Code Wiget <[hidden email]>:
Hey everyone,

How do you go about EUnit testing that requires the whole application to be running before the test ?

For example, my erlang application starts one pool of processes that connects to a database and another that connects to another server in our backend. To run any real tests, I’m going to need to have one or both of those systems up and running. The way that I’m doing is right now is below, and it is very cluge-y feeling:

ok = application:start(compiler),
ok = application:start(syntax_tools),
ok = application:start(goldrush),
ok = application:start(gproc),
ok = application:start(gen_logger),
ok = application:start(pooler),
ok = application:start(quickrand),
ok = application:start(re2),
ok = application:start(lz4),
ok = application:start(uuid),
ok = application:start(semver),
ok = application:start(snappy),
ok = application:start(cqerl),
ok = application:start(ecpool),
ok = application:start(esockd),
ok = application:start(lager_syslog),
ok = application:start(lager),


This system works because none of the above applications require any environment variables from a config file. So some of my other applications can’t run using this. Is there any way to have eunit run the test after starting the whole application? 

Thanks!



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Eunit testing after starting the application

Code Wiget
I found this:
ERL_AFLAGS="-config etc/server.config" rebar3 eunit

This will set the config file to etc/server.config before compiling and running the eunit testing.

So in combination with ensure_all_started, then we can start the code necessary to run without the common test framework. This gets around the need to export functions for the common test framework so that we can test the internal functions.

On May 31, 2018, 12:52 PM -0400, Code Wiget <[hidden email]>, wrote:
Nathaniel,

Thank you - ensure_all_started is going to save me dozens of lines of code in other locations =).

Gleb,

Are you suggesting not doing eunit testing and just running with common tests and using init_per_testcase ? I get that EUnit is easy, but for an application that is already built, when we are trying to test system functionality, maybe it is better to just go full on with the common test suite?



On May 31, 2018, 11:42 AM -0400, Gleb Vinogradov <[hidden email]>, wrote:
You can use CommonTest to bootstrap your application. Set environment variables, start applications etc in CommonTest and run EUnit test then.

2018-05-31 22:24 GMT+07:00 Code Wiget <[hidden email]>:
Hey everyone,

How do you go about EUnit testing that requires the whole application to be running before the test ?

For example, my erlang application starts one pool of processes that connects to a database and another that connects to another server in our backend. To run any real tests, I’m going to need to have one or both of those systems up and running. The way that I’m doing is right now is below, and it is very cluge-y feeling:

ok = application:start(compiler),
ok = application:start(syntax_tools),
ok = application:start(goldrush),
ok = application:start(gproc),
ok = application:start(gen_logger),
ok = application:start(pooler),
ok = application:start(quickrand),
ok = application:start(re2),
ok = application:start(lz4),
ok = application:start(uuid),
ok = application:start(semver),
ok = application:start(snappy),
ok = application:start(cqerl),
ok = application:start(ecpool),
ok = application:start(esockd),
ok = application:start(lager_syslog),
ok = application:start(lager),


This system works because none of the above applications require any environment variables from a config file. So some of my other applications can’t run using this. Is there any way to have eunit run the test after starting the whole application? 

Thanks!



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions



_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Eunit testing after starting the application

Przemysław Simon Zelazny
In reply to this post by Code Wiget

>
> Are you suggesting not doing eunit testing and just running with common
> tests and using init_per_testcase ? I get that EUnit is easy, but for an
> application that is already built, when we are trying to test system
> functionality, maybe it is better to just go full on with the common
> test suite?

Hi,

from my experience, if you've inherited a big, untested application that
you want to put tests around, trying to start from a "unit-test" level
will be 1) difficult, 2) counterproductive.

1) is because you're trying to capture units of functionality when it's
clear that the application was not designed in a modular, isolated
fashion. So you end up launching-the-world (or mocking-the-world), which
is tedious and leads to..

2) counterproductive, brittle tests. You're now baking in the coupling
that the application has to its dependencies and making that coupling a
contract. You're only adding to the snowball that you've got.

Instead of the above, I'd recommend putting in place a suite of true
end-to-end tests, and capturing the black-box behavior of your system.

# Makefile
.PHONY: all rel run e2e-test

all: rel run e2e-test
        @echo "E2E tests passed"

rel:
        rebar3 release
run:
        _build/blahblah/yourapp start
        wait_for_it localhost yourport

e2e-test:
        rebar3 ct


Now, your Common Tests will have to assume some things about the system,
but these assumptions will only reveal what your clients are assuming
anyway. The benefit is you've decoupled knowledge of internals from a
behavioral specification of your system.

Now, you can go in and re-write/re-factor particular modules, and cover
them with true unit tests, eliminating as much coupling as possible.

See here: https://mike-bland.com/2011/11/01/small-medium-large.html for
a nice overview of testing levels at Google.

Cheers,
Simon Zelazny


>
>
>
> On May 31, 2018, 11:42 AM -0400, Gleb Vinogradov
> <[hidden email]>, wrote:
>> You can use CommonTest to bootstrap your application. Set environment
>> variables, start applications etc in CommonTest and run EUnit test then.
>>
>> 2018-05-31 22:24 GMT+07:00 Code Wiget <[hidden email]
>> <mailto:[hidden email]>>:
>>
>>     Hey everyone,
>>
>>     How do you go about EUnit testing that requires the whole
>>     application to be running before the test ?
>>
>>     For example, my erlang application starts one pool of processes
>>     that connects to a database and another that connects to another
>>     server in our backend. To run any real tests, I’m going to need to
>>     have one or both of those systems up and running. The way that I’m
>>     doing is right now is below, and it is very cluge-y feeling:
>>
>>     ok = application:start(compiler),
>>     ok = application:start(syntax_tools),
>>     ok = application:start(goldrush),
>>     ok = application:start(gproc),
>>     ok = application:start(gen_logger),
>>     ok = application:start(pooler),
>>     ok = application:start(quickrand),
>>     ok = application:start(re2),
>>     ok = application:start(lz4),
>>     ok = application:start(uuid),
>>     ok = application:start(semver),
>>     ok = application:start(snappy),
>>     ok = application:start(cqerl),
>>     ok = application:start(ecpool),
>>     ok = application:start(esockd),
>>     ok = application:start(lager_syslog),
>>     ok = application:start(lager),
>>
>>
>>     This system works because none of the above applications require
>>     any environment variables from a config file. So some of my other
>>     applications can’t run using this. Is there any way to have eunit
>>     run the test after starting the whole application?
>>
>>     Thanks!
>>
>>
>>
>>     _______________________________________________
>>     erlang-questions mailing list
>>     [hidden email] <mailto:[hidden email]>
>>     http://erlang.org/mailman/listinfo/erlang-questions
>>     <http://erlang.org/mailman/listinfo/erlang-questions>
>>
>>
>
>
> _______________________________________________
> erlang-questions mailing list
> [hidden email]
> http://erlang.org/mailman/listinfo/erlang-questions
>

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions