The terms "test function" and "ansatz" are more general. In my experience, the term "test function" is largely synonymous with "trial function" and is often used in connection with variational methods such as the Ritz method. A typical usage is one where the test function is a linear combination of basis functions, but the term is not restricted to this case and can refer to any parameterized function that selects a subset of the function space of interest. The term "ansatz" is largely synonymous, except perhaps it's less strongly associated with variational methods and refers more generally to any attempt to write down a solution in parametrized form. The literal meaning of the German word "Ansatz" from which this term is derived is something like "approach"; that is, an ansatz is a certain way of approaching the problem by choosing a particular functional form.
The term "basis function", by contrast, is only used in the linear case and refers to one of the functions from whose linear combinations the test function is formed.