Common test init_per_group/2 terminates gen_server when it is started with gen_server:start_link.
But it is ok to start server with gen_server:start.
gen_server can be started with any of these methods (start and start_link) in init_per_suite/1 and init_per_testcase/2.
Why it is not possible to start gen_server in init_per_group/2 with gen_server:start_link?
This happens because
init_per_groupis run in a separate process, just like each test case, and that process exits with an exit reason that communicates information about success/failure of group initialisation. Fromtest_server:run_test_case_eval:Since the
gen_serveris linked to the process that runsinit_per_group, and since the exit reason is notnormaland thegen_serveris not trapping exits, thegen_serverprocess exits with that same exit reason.On the other hand,
init_per_testcaseis run in the same process as the test case itself, so this problem does not appear.