united-states
Absent an agreement to the contrary, the employer can make expert testimony a requirement for further employment, and the employee can quit if this is not acceptable. As a practical matter, employees almost always agree to do so without any serious objections to testifying as experts on behalf of their employers.
Also, U.S. courts distinguish between retained and non-retained expert testimony.
A retained expert is someone testifying solely because they were hired to do so in particular case.
A non-retained expert is someone who has personal knowledge of the events in the case who has expertise in an area and is being asked to testify about that personal knowledge in a manner informed by that person's expertise.
A non-retained expert can be compelled to testify by subpoena, even if an agreement for that person to testify as an expert voluntarily is not reached.
Many employees asked by an employer to provide expert testimony would fall in the category of a non-retained expert who could be compelled to testify about the matter from their personal knowledge in a manner informed by their expertise, even if they quit.
But, a non-retained expert can only be compelled to testify at trial, not to cooperate in preparing for that testimony with an attorney for the employer or preparing a written report in advance of that testimony.
Incidentally, it would be the rare exception to the rule for the written report of a retained expert witness in advance of their testimony at trial or in a deposition to make that report stating that opinion under oath. Typically, it would be signed but not sworn to by the expert.
the court requires
(version 1) the company (version 2) someone with expertise from the
company to provide a sworn opinion (something like "the process to do
X is Y"), and answer questions in court.
In U.S. cases, it isn't "the court" that is proactively telling litigants what evidence they have to provide. The law tells litigants what has to be proved.
Sometimes, in U.S. non-criminal litigation, expert testimony from someone is required to proven or disprove an element of a case.
For example, in professional malpractice cases, someone with expertise in that profession must testify that the professional did or did not perform the work which is the basis of the lawsuit in a manner that falls below the standard of care for a professional of that type.
Other times, expert testimony is one means of many possible means to prove a fact in the case.
For example, one could prove lost profits by showing that a specific contract was lost by someone's action, or one could instead hire an expert to show what profits could have been earned if something was done.