I have looked up the word exam in Cambridge dictionary, Merriam-Webster and Longman. According to these dictionaries, the longer form examination is formal, but that doesn't mean that the shorter word is necessarily informal, does it? I realise that in a really formal text, examination would probably be the better choice, but would it be ok to use exam in "medium formal" texts, such as, for instance, an academic thesis?
Yes, it definitely can and often does occur in all kinds of formal contexts, ranging from school schedule announcements, to research papers, to reports.
Just a quick example, since you mentioned "academic thesis":
Cytokine Dysregulation Associated with Exam Stress in Healthy Medical Students (source)
The mechanisms of stress-related immune alterations have not been fully elucidated. Cell-mediated immune responses as well as antibody and certain cytokines are reported as being suppressed during times of high stress. However, the role of suppression vs dysregulation has not been established in human stress models. The effect of exam stress on regulatory cytokines in 16 healthy medical students was assessed by measuring type-1 (IFN-γ) and type-2 (IL-10) cytokines from 72-h PHA/PMA-stimulated PBMC 4 weeks before and 48 h after exams. Results demonstrated decreased IFN-γ accompanied by increased IL-10 during exam stress that resulted in a decreased IFN-γ:IL-10 ratio. There was a significant correlation between the cytokine response to PHA/PMA and number and subjective adjustment to daily hassles. Additionally, students who reported greater levels of loneliness also reported greater numbers of and poorer subjective adjustment to hassles. The differences were consistent in both males and females but did not correlate with AM cortisol levels. Additionally, when individuals were grouped into high vs low preexam hassle levels, the type-1/type-2 shift in the IFN-γ:IL-10 ratio occurred in the low hassles group only. These data suggest that psychologically stressful situations shift type-1/type-2 cytokine balance toward type-2 and result in an immune dysregulation rather than overall immunosuppression. This may partially explain the increased incidence of type-2-mediated conditions such as increased viral infections, latent viral expression, allergic/asthmatic reactions, and autoimmunity reported during periods of high stress.