jeudi 14 février 2019

CastTo

I want to quickly run through some tests for a small app i made.

I havent used mock nor the design pattern that would require it. But need access to something like

public class Stuff : Monobehaviour{
    public int AddOne(){
       return 1;
     }
}

This is a nice fix for me to get mono behaviour working in unity tests.

public static class TestableObjectFactory {
    public static T Create<T>() {
        return FormatterServices.GetUninitializedObject(typeof(T)).CastTo<T>();
    }
}


var testableObject = TestableObjectFactory.Create<Stuff>();
Stuff.AddOne();

And i have used it before. Why is CastTo no longer working?

Aucun commentaire:

Enregistrer un commentaire