You will have to introduce an interface which exposes a method to create the instance from the type. Have your class take an implementation of the interface in its constructor.
Then you can mock that.
You then have an implementation which just delegates to Activator.CreateInstance which you use in Production.
That said, why do you need to mock this? Why can't your test just check that it gets back the type that was specified in the method call?
Following On from your edit, why can't you mock the factory call to BuildChild rather than the call inside the factory. That seems like the dependency that you want to mock.
seems you either want to test that the factory returns the correct type, which you don't need to mock anything for, or you want to introduce an interface for your factory and mock that.
I think that wanting to mock Activator.CreateInstance is your code telling you that something is not quite right with your design.
you could test your factory implementation without having an implementation of AnAbstractClass or without needing to mock anything like this I think:
create a test implementation:
public class TestAnAbstractClass : AnAbstractClass
{
public object ConstructorParameter;
public TestAnAbstractClass(object constructorParameter)
{
this.constructorParameter = constructorParameter;
}
}
then call your factory with this in your test:
[TestMethod]
public void TestBuildChild()
{
var type = typeof(TestAnAbstractClass);
var parameter = "A parameter";
var child =(TestAnAbstractClass) this._factory.BuildChild(type, parameters);
Assert.That(child.ConstructorParameter, Is.EqualTo(parameter));
}
Then you are testing the factories actual functionality and even if the implementation changes the test won't need to, and you test all the code.