I have file in src/Form/TestForm.php.
I would like to add link of Forgot password in buildForm function & want to display in twig template file.
How to achieve this?
You should add the link in the form builder, something like the following example:.
$forgot_password_link = \Drupal\Core\Link::createFromRoute($this->t('Password link'), 'user.pass')->toRenderable();
$form['forgot_password_link'] = [
'#markup' => render($forgot_password_link),
];
You can add links in Twig directly:
<a href="{{ path('user.pass') }}">{{ 'Forgot password?'|t }}</a>
see https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates
src/Form/
and notsrc/form/