Increment counter only if no page break occurs

I'm trying to create a form that contains a series of test instructions, each of which are represented as minipages and take up between 1/3 - 1/2 of a standard A4 page. What I'd like is to be able to display the number of tests on a page within the foot of each page.

I've created a counter that increments whenever a test is added and is reset whenever the page counter increments. However, I'm finding that the test counter increments even if the test ends up on the next page due to inadequate space. Is there a way that I can make the counter report the correct number of tests on each page?

Included is a MWE:

\documentclass[10pt,a4paper]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}

\rfoot{\large{$\dfrac{}{\arabic{PageTestCounter}}$}}

\newcounter{PageTestCounter}[page]

\stepcounter{PageTestCounter}
Test #1:\hspace{1cm}$\square$
\vspace{25\baselineskip}
}

\begin{document}

\pagestyle{fancy}

\end{document}


The output from the MWE:

-

You should use a \mark command e.g. with the extramarks package:

\documentclass[10pt,a4paper]{article}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyhdr}

\rfoot{\large{$\dfrac{}{\lastxmark}$}}

\usepackage{perpage}
\newcounter{PageTestCounter}
\MakePerPage{PageTestCounter}

\stepcounter{PageTestCounter}%
Test #1:\extramarks{}{\arabic{PageTestCounter}}\hspace{1cm}$\square$
\vspace{25\baselineskip}%
}

\begin{document}

\pagestyle{fancy}


You can also use the normal \markboth, but probably you will need it for section.