# Undefined function when running common tests

**URL:** <https://erlangforums.com/t/undefined-function-when-running-common-tests/2205>\
**Category:** Questions / Help\
**Tags:** common-test\
**Created:** [December 27, 2022, 8:52am UTC](https://erlangforums.com/t/undefined-function-when-running-common-tests/2205 "2022-12-27T08:52:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfetahe](https://erlangforums.com/letter_avatar_proxy/v4/letter/a/779978/32.png) [@alfetahe](https://erlangforums.com/u/alfetahe)\
**Post date:** [December 27, 2022, 8:52am UTC](https://erlangforums.com/t/undefined-function-when-running-common-tests/2205/1 "2022-12-27T08:52:00Z")

</div>

Hello, could anybody point out some mistakes I am doing or give some guidance on why my function is undefined when running the common tests.

I have the following file `/src/config_handler.erl`

```erlang
-module(config_handler).

-export([election_delay/0]).

election_delay() ->
    application:get_env(elector, election_delay, 3000).

```

My test file is `/test/config_handler_SUITE.erl`

```erlang
-module(config_handler_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-export([groups/0, all/0, init_per_group/2, end_per_group/2]).
-export([election_delay_test/1]).

groups() ->
    [{config_handler_group, [], [election_delay_test]}].

all() ->
    [{group, config_handler_group}].

init_per_group(_GroupName, Config) ->
    Config.

end_per_group(_GroupName, _Config) ->
    application:set_env(elector, election_delay, 3000).

election_delay_test(_Config) ->
    application:set_env(elector, election_delay, 5000),
    ?assert(config_handler:election_delay() == 5000).

```

When running the test with: `ct_run -dir test -logdir test_logs`

I get:  
=== === Reason: undefined function config\_handler:election\_delay/0  
in function config\_handler\_SUITE:election\_delay\_test/1 (config\_handler\_SUITE.erl, line 21)  
in call from test\_server:ts\_tc/3 (test\_server.erl, line 1782)  
in call from test\_server:run\_test\_case\_eval1/6 (test\_server.erl, line 1291)  
in call from test\_server:run\_test\_case\_eval/9 (test\_server.erl, line 1223)

I am not sure why the function is undefined although it is defined and exported. Does anybody else have any ideas?  
Thanks in advance 🙂 I recently started coding in erlang so I might be doing some stupid mistakes that I am not aware of.

---

<div class="post-metadata">

**Author:** ![mmin](https://erlangforums.com/user_avatar/erlangforums.com/mmin/32/2193_2.png) [@mmin](https://erlangforums.com/u/mmin)\
**Post date:** [December 27, 2022, 9:16am UTC](https://erlangforums.com/t/undefined-function-when-running-common-tests/2205/2 "2022-12-27T09:16:38Z")

</div>

The problem is that module `config_handler` is not loaded.

`ct_run` will run a new Erlang VM and by default it doesn’t know where your compiled code is located. Try adding flag `-pa <path_to_directory_contatining_.beam_files>`, e.g. `ct_run -dir test -pa ./ebin`. This way, compiled code that is placed on the specified path will be loaded by the VM on startup and CT can access it.

Try reading [this](https://learnyousomeerlang.com/modules) and try few examples from [this](https://learnyousomeerlang.com/common-test-for-uncommon-tests) to get familiar with CT.

---

<div class="post-metadata">

**Author:** ![alfetahe](https://erlangforums.com/letter_avatar_proxy/v4/letter/a/779978/32.png) [@alfetahe](https://erlangforums.com/u/alfetahe)\
**Post date:** [December 27, 2022, 9:22am UTC](https://erlangforums.com/t/undefined-function-when-running-common-tests/2205/3 "2022-12-27T09:22:53Z")

</div>

Working now when added the `-pa <path_to_directory_contatining_.beam_files>`to the ct\_run command. Thanks!
