How can I programmatically add a field to a field group? I have tried this code but it is not working.

$form['field_test'] = [
  '#title' =&gt; t('test'),
  '#type' =&gt; 'radios',
  '#options' =&gt; [t('A'), t('B'), t('C')],
 ];
$form['#group_children']['field_test'] = 'group_1';


I also tried with 

$form['#fieldgroups']['group_1']-&gt;children[] = 'field_test';


But nothing is working. It works in Drupal 7. Is it changed in Drupal 8?

I have written this code in hook_form_alter and I'm altering a node form.
You have to put both.

$form['#group_children']['field_test'] = 'group_1';
$form['#fieldgroups']['group_1']-&gt;children[] = 'field_test';