Caption inside table and listoftables

I currently use a straightforward solution to get captions inside the table. However it does not allow the tables to be listed in the "\listoftables": Example:
and the code:

\documentclass[12pt,a4paper]{article}

\begin{document}

\begin{table}
\refstepcounter{table} \label{mytable}
\begin{tabular}{|c|}
\hline
Table \ref{mytable}: The test table\\\hline
contents\\\hline
\end{tabular}
\end{table}

\listoftables

\end{document}


Is there a way to get \listoftables working with my solution?
Thank you for any ideas

It's relatively easy. Look at the aux file to see how a normal caption does it.

\documentclass[12pt,a4paper]{article}

\begin{document}

\begin{table}
\refstepcounter{table} \label{mytable}