Skip to main content
Updating link to Unity test framework
Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

Use the unit test framework 'Unit Test Tools'unit test framework 'Unit Test Tools' provided by Unity.

You're right you can't create new MonoBehaviours on their own, but why not use an empty GameObject and use AddComponent<MyMonoBehaviour>() and then run your tests?

Alternatively you can create the bulk of your logic inside your own classes. Then your MonoBehaviour scripts will just use composition to have a local instance of the class that represents their functionality. Your unit testing can also just make a local instance of the class. Though, this sounds more messy than the Humble Object pattern suggested in the blog post.

Yes, creating a testing framework and implementing unit tests can be complex. But once you have things in place, adding additional unit tests is fairly trivial.

Use the unit test framework 'Unit Test Tools' provided by Unity.

You're right you can't create new MonoBehaviours on their own, but why not use an empty GameObject and use AddComponent<MyMonoBehaviour>() and then run your tests?

Alternatively you can create the bulk of your logic inside your own classes. Then your MonoBehaviour scripts will just use composition to have a local instance of the class that represents their functionality. Your unit testing can also just make a local instance of the class. Though, this sounds more messy than the Humble Object pattern suggested in the blog post.

Yes, creating a testing framework and implementing unit tests can be complex. But once you have things in place, adding additional unit tests is fairly trivial.

Use the unit test framework 'Unit Test Tools' provided by Unity.

You're right you can't create new MonoBehaviours on their own, but why not use an empty GameObject and use AddComponent<MyMonoBehaviour>() and then run your tests?

Alternatively you can create the bulk of your logic inside your own classes. Then your MonoBehaviour scripts will just use composition to have a local instance of the class that represents their functionality. Your unit testing can also just make a local instance of the class. Though, this sounds more messy than the Humble Object pattern suggested in the blog post.

Yes, creating a testing framework and implementing unit tests can be complex. But once you have things in place, adding additional unit tests is fairly trivial.

Source Link
House
  • 73.3k
  • 17
  • 185
  • 273

Use the unit test framework 'Unit Test Tools' provided by Unity.

You're right you can't create new MonoBehaviours on their own, but why not use an empty GameObject and use AddComponent<MyMonoBehaviour>() and then run your tests?

Alternatively you can create the bulk of your logic inside your own classes. Then your MonoBehaviour scripts will just use composition to have a local instance of the class that represents their functionality. Your unit testing can also just make a local instance of the class. Though, this sounds more messy than the Humble Object pattern suggested in the blog post.

Yes, creating a testing framework and implementing unit tests can be complex. But once you have things in place, adding additional unit tests is fairly trivial.