Unit Testing with Unity

preview_player
Показать описание

-------

I recently started Unit testing some of my bigger Unity3D projects and wanted to share how and why I'm doing it. If you've never tried out unit tests in your unity project, give it a shot, it may save you a ton of time and pain :)

Рекомендации по теме
Комментарии
Автор

I would love to see video on getting started with unit testing. These are practices I really want to learn.

danielrousseau
Автор

I very much appreciate these kinds of videos. A lot more so than "how to make minecraft in unity" . These are gonna teach immensely more to people in the long run. Your explanation is also very clear and understandable. So, great job.

guraysenova
Автор

Unit tests are integrated in cloud build now too, and we are looking at setting up a test driven build pipeline so I’m coming back to this idea that I leaned from you a long time ago and revisiting.

justinwhite
Автор

There just aren't that many videos on Unit testing with Unity3D. I do very much watch your videos and pay attention to what you're teaching. Thank you!

VgManiac
Автор

Awesome video. I would definitely love to learn more about unit testing. Thanks for consistently putting out great content

jaredhenning
Автор

Sounds interesting and really helpful! Would love to see more videos about it

Pedroantos_
Автор

I'm also interested in some of the more useful examples of using Unit Testing in Unity, including on MonoBehaviours even if it is more difficult. I think the idea of coding some extra methods to ensure that things are behaving as expected BEFORE play-testing a build is a great idea and has potential to save a ton of pain, but I'm unsure how a typical Unity game might set up some useful Unit Tests.

beardordie
Автор

Awesome video...and yes... more testing videos please :)

yizzie
Автор

Yes please on a more involved look at properly implementing unit testing.

TheSpacecraftX
Автор

Really interested too in seeing more about this subject, as a beginner i want to do it the best way, not the easiest. Thanks !

kimchitool
Автор

I'd love some videos on QA techniques using Unity - from what they are, why you would use them, to how they're done. Thank you for ones on Unit Testing videos - learned a lot! +Unity3d College

ramkaundinya
Автор

I have felt so naked when working with Unity since there was a lack of testing. Now that it exists I'm excited to write more in Unity, with tests backing up everything.

As for suggestions on better testing, here is what I can give you:

1. Use multiple tests per method. In practice I like to use a minimum of 3 when one parameter is involved: one to test the method in the usual manner, another using the most extreme possible parameters to cover corner cases, and another using invalid parameters to cover edge cases. Then when there are more non-related parameters, add two more for each for corner/edge case possibility for good measure. They're fast, so why not?

2. You mentioned using variables in the example test, You can dry things up by initializing these in a constructor for the test class. Each will be available in each example, as well as reset each example, and make testing it faster.

3. You can create mock classes in a separate folder, and reference when needed for parameters. Set these Mock classes to use static member properties, and single line methods with static return values. In areas where these objects are needed as parameters you can use the mock and avoid the need for an instance of an object that adds overhead. Overall, this will allow your tests to run much quicker, as well as allow you to test areas quickly and easily.

3b. I've noticed that when your test script name matches that of the associated script, the inspector will show the test script initializes a lot of the game objects for you. While I haven't really tried to access these yet, I'm not sure that it would be much better than using Mocks, but I could be very wrong.

4. Unity offers Play tests to also offer acceptance/integration tests, giving you access to all MonoBehavior states. While you won't need as many of these, this is a great way to test behaviors across multiple classes and components. While I personally have not dived into the complete ability, I do know you have the ability to pause the state, and test state prior to an event. I could see these being great for testing state in high-traffic areas. By the way, these are very slow; it uses its own player window after all.

5. Lastly, just a FYI more than anything. I found that Unity 2018.2 did not require a specific folder name. As long as you create the folder from the TestRunner you should be golden. In my own test project, I have the folders EditTests, and PlayTests, where the Test Runner sees them without any issue.

Anyways, I hope that even just one of these helps with your testing progress, and hope to see more Unity testing in the future! :)

vilesyn
Автор

yes please! teach more about unit testing please :D

Tincho_Zerox
Автор

Would like more videos on this subject.

ShiroyashaGin
Автор

Very interested to know more about Unit testing in Unity and about some common cases.

pyrog
Автор

+1 also interrested in how to structure a project to easily integrate testing

TriteanRares
Автор

I unit test non MonoBehaviour derived classes, though when I do unit test I make heavy use of Mocks via NSubstitute. I am not a fan of stub behaviours because they can lead to unexpected outcomes.

JasonStorey
Автор

I would like to see more unit testing videos

neevir
Автор

Hi Jason. Want to ask about this. Unit testing should be fast right? But I'm trying on unity, even if we just change 1 word of code, save and get back to unity already takes 2 seconds alone and not even running the test.

What do you think about it? And do you have solution for this? Thank you Jason.

daryladhityahenry
Автор

Count me interested in more unit testing!
Your usual demonstration breakdowns are pretty well organized already, but at least one introductory and one intermediate level demos would be also awesome! There are quite a bunch of really good Unity and C# guide channels nowadays like Brackeys or Sebastian Lague and you especially, but most of the stuff get handled in Youtube kind of feels like they have tendency to only stick to the very basic ones which is shame...

ho-jeonglee