Unit Tests in Unity
Sign up for the Level 2 Game Dev Newsletter: eepurl.com/gGb8eP
In this video I'll show you how to write more effective Unit Tests in Unity. More importantly, I'll demonstrate how valuable Unit Tests can be for Unity projects of any size and Unity developers of any skill level.
#Unity3D #UnityTutorial #GameDevelopment
📦 Download the code at / 37986282
👨💻 Join our community: / discord
❤️ Support the channel: / infalliblecode
My Favorite Unity Assets 💯⤵️
1️⃣ Odin Inspector: assetstore.unity.com/packages...
2️⃣ Shapes: assetstore.unity.com/packages...
3️⃣ Easy Save: assetstore.unity.com/packages...
4️⃣ Dialogue System for Unity: assetstore.unity.com/packages...
5️⃣ Editor Console Pro: assetstore.unity.com/packages...
⚡ Learn more about Unity 3D Plus at prf.hn/click/camref:1100l3e8M/...
👋 Contact me directly at charles@infalliblecode.com
* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.
Пікірлер: 180
NEXT VIDEO: Design Patterns in Game Development 👉 kzread.info/dash/bejne/o4dmtbKlY6qrY84.html
@mrkhan8631
3 жыл бұрын
I have too sheep but it's real
This format is like watching an E3 gameplay presentation with "real" in-game chat.
@Sergalt
4 жыл бұрын
heh, yea that is not how 2 programmers talk with one another xD
@InfallibleCode
4 жыл бұрын
@@Sergalt lol you're right - that's how a crazy programmer talks to himself xD
@Sergalt
4 жыл бұрын
@@InfallibleCode well, the only unrealistic way is how nice you are xD
@lesthodson2802
2 жыл бұрын
I hate this format.
Dialogue feels like an english lesson for beginners where they try to retain pauses between sentences and use most simple words for those who haven't learned complex dictionary
@InfallibleCode
3 жыл бұрын
lmao
2:43 "And it looks like all the other vectors line up aswell" N E W S yap, looks good to me :)
@HassaanALal
2 жыл бұрын
xddd
Hey mate, if you find pressing triangles to browse hierarchy not so excited as the rest of the video may I suggest you pressing it once while holding Alt key to reveal whole structure.
@nachtwindstudios3406
2 жыл бұрын
Dayum, didn't know that O.o Thanks a lot!
@evanlane1690
Жыл бұрын
BEST PART OF THIS TUTORIAL! Thanks Maks!
@Star_Wars_Galaxy
Жыл бұрын
lifesaver, thank you!
I love how you do not just say "It's good to do this and that!" but actually create a well known scenario that leads to that conclusion. Well done!
Wait a second! they both have the same laugh!
This video is criminally underrated. I learned way more from it than I thought. Kudos for you!
As usual a really nicely produced, clear and interesting video. It would have a made a better demo of testing to have replaced the bug, so that your test was red until you fixed the code.
"Fair enough" -Charles, 2020
@InfallibleCode
4 жыл бұрын
😂
This is one of the most comfortable vids for coding ive ever watched, very informative and the creativity of the making of the vid makes this easy to understand
This was a really good informative video. The structure of having one person teaching someone else was done quite well and did a good job of getting across the relevant information in an effective and approachable fashion. Great job!
Man, this tutorial was such great content. I now fully understand what each of the features of the UTF do, and how to implement unit tests into my own fast-growing bug-infested project!
I think its worth mentioning the 3 A's of unit tests: arrange, act, assert.
@InfallibleCode
4 жыл бұрын
That's a great point! I'm thinking of doing follow up to cover some of the basics of writing Unit Tests and the gotchas that are associated with play mode tests.
@Spherous
4 жыл бұрын
@@InfallibleCode great idea! I don't know much about them in traditional Unity, I've only written unit tests for DOTS which doesn't suffer from the runtime gotchas.
@Zeuts85
2 жыл бұрын
Personally I prefer Given, When, Then - because to me it flows more like a coherent thought. "Given these preconditions, when I do X, then Y should happen."
Amazingly well put together video, I appreciate how you have structured it like a tutoring session. It might seem a little cringy at first but I think it really helps with making me engaged like I am actually being taught. Keep up the good work!
Thank you :) These videos are always quite helpful!
Thanks for the video. Like you and your friend Barles, I actually enjoy writing unit tests. I'm new to Unity and decided I was going to start my first project off on the right foot. After a couple weeks of getting up to speed on Unity / VR, I'm ready to start a small project and this video was exactly what I needed to get me going. FYI, love the Charles/Barles thing. That's a fun twist!
Usually I don't like heavily scripted tutorials but I am loving this format! Thanks! Liked, shared and subscribed!
One of the best tutorials I have ever seen. Thanks!
Great tutorial, I'm eager to set up robust unit testing in my project. One note: it's not strictly necessary to create a new assembly definition in order to use EditMode tests. As shown in the message at 5:53, EditMode tests can be placed into the "editor special folder". Any script that is placed within a directory named "Editor" will be associated with the Assembly-CSharp-Editor.dll assembly, rather than the Assembly-CSharp.dll assembly. I mention this because my project uses a third-party UI library that is not currently structured in a way to easily create a new assembly definition without massive code reorganization or cyclic dependencies. Using the "Editor" folder won't offer the compile-time improvements of splitting up code into different assemblies, but it will get you up and running with unit tests. Thanks again!
@TechnologicNick
Жыл бұрын
Thanks a lot, I spent 6 hours messing around with Unity assemblies and your comment just solved my problem!
man you are helping TONS of people, thank you.
Not exactly what i was looking for, but this saved my life. Thanks, man.
Nice format as usual, really enjoy it :)
Great video, been meaning to dig deeper into unit tests. Thanks.
Thanks for making these guides! Working as a Java system developer in my day job I cannot put enough emphasis on how important unit tests are once your code base starts growing past the first few thousand lines of code. You implement something new here, and something random breaks over there. With no tests, those kind of bugs are real hard to spot before launch. As many developers-in-training use your guides as a starting point, it would be great if you put some emphasis on code conventions in your examples. Using conventions like given_when_then (givenSheepInScene_whenKeyPressUp_thenSheepMovesUp) or functionName_testState_expectation (move_isUp_sheepMovesUp) will really help in the long run.
I love how you and your alter rubber ducky ego are taking this so calmly and in an upbeat manner. I'd like to say that I speak for everyone when I say that debugging usually goes with a lot of silence and a dejected sigh at the end when the bug is finally found. Or loud expletives all the way through. It's funny how there's rarely any in between.
Unit tests also useful for debugging. Unity runs them as regular code with all debuggers attached. You can make special tests that reproduce the bug, set breakpoints, and step through code. Saves a lot of time especially for those bugs that occur one in a blue moon.
Awesome tutorial, exactly what I was looking for!
Your videos are always super helpful and easy to follow. Thanks
Thank you, for a good start to create the unit test in Unity
Excellent example about unit testing your videos about learning mid-advanced C#-Unity are the best sir!
Damn this format is so helpfull! Nice job !
Thanks you I watch the whole Unity Conference about it and this video was waaaaaay more usefull
@InfallibleCode
2 жыл бұрын
Wow that means a lot! I’m so glad you found it useful :D
Thanks for this great video. I understood something that I hadn't caught in a video in my native language.
Brilliant! Love you and your channel!
Thank you for this video! I tried several tutorials on this subject and they were all overcomplicated involving manually creating the assemblies and I couldn't get anything to work properly. Your video was helpful and funny. I'll probably be watching others in the series as I'm trying to learn Unity development.
What I'm finding very useful is for Editor UT's that check to see if my scene has the right root objects, that child objects are set static, that they have shadows turned off.. have collision boxes etc.. Extremely useful as this stuff gets screwed up all of the time and I've been writing my own tech mechanism for this.
Thanks! I guess a complex video to make and in the end, you made it simpler to understand. So, good teaching job, and thank you again!
So much cheese and good advice. Thanks - both of you - get the first test failing then passing.
This is brilliant, thank you
Thanks buddy. Nice intro to unit testing in Unity :D
Nice presentation for learners, good teacher!
Snooped on your Spotify- Griz has some absolute bangers
As a start and understand why it is important I think it is a good video ;)
Wow... Thanks for the great tutorial!
Great format, great job
Good job mate, helped a lot!
love this guy
This is awesome! Thanks a ton!!
Neat introduction. In other cousins areas we tend to define the atomic unit as a domain aggregate as the classes and properties that belong to that aggregate are internal to that feature. In this case, if the move code cannot exist without the player code then all you're doing is reproducing work. The higher up object wins as that is the interaction point.
Great video thank you!
Awesome tutorial!
This video is like SO good thank you very much for this nice content (just found your channel)
Thank you! Btw, how do you mock dependencies?
Good format for teaching.
I like the way of presenting .. basically storytelling...keep going...
Thank you man!!!!! You are awesome
The caller is Charles, so is the other guy... Barles? Is that what he said?
@InfallibleCode
4 жыл бұрын
Yep! Thanks for tuning in to The Adventures of Charles and Barles: A Game Developer Slowly Slipping into Insanity!
@coolmatt3906
3 жыл бұрын
@@InfallibleCode Barles is so nice. Is he ever a jerk, like buzz off Charles, I've got real work to do.
Thank you!
This video is very useful thank you for sharing this with us :)
That was a very practical video, thank you! As a programmer, I'd say the naming of tests isn't perfect, but that's not the main point here.
We love to see some good programming practices tutorials on Unity, for some reason that is something that is sorely lacking on most tutorials.
Thanks !
I'd say that was a perfect example when not to waste your time on unit testing
It is also possible to run/debug tests directly from Rider.
Bruh tests for every function in an already huge codebase are a gigantic pain in the ass.
@JC.72
3 жыл бұрын
I remember seeing somewhere some shared the idea develop with testing in mind from the start. Maybe it can be somehow added in during dev sort of like a habit like how we often comments on code.
Hey, Very well done tutorial! Thank you and greetings :-)
But what if I need to test some kind of manager? Do I need to fill all the dependencies? Sounds like a huge set up there
Thanks
Hi Charles/Barles =) Thank you for the videos. I like to use the more serious parts that you show. It really does simplify the code and makes it easier to reuse! I have some UnityTest, which is almost the same, except the parameters. For my normal tests I can use the [TestCase(5f,true)] attribute for e.g. TakeDamageTest(float damage, bool isAliveAfterwards) and easily test multiple scenarios with the same test. Can this be done for the [UnityTest] as well somehow?
okay I'm ngl, at first I HATED the format this was in, but having stuck through it after the first minute or so it was really REALLY good. So, sorry for having so little patience! And if you're reading this, it's definitely worth the lil setup
Hope can make more advance video about unit test like your Zelda TDD course.
yeap works like a charm!
Is it recommended to write both edit and Unity tests in the same c# file?
On Mac, is it not supported to dock a window in the editor? On top of that, I can't switch between editor and test runner. Sometimes it happens when I press command+tab but only once.
Nicely made, really should try. But wondering about testing the Direction: Wouldn't it be better to test against i.e. Vector3.Up? I feel it is a bit useless to test for new Vector3(0,1,0) in Testcode, as you could do the same mistake as in production code.
Is it possible to do tests on items created in the Hierarchy window as opposed to the Project dropdown? I created several component scripts in the Project window, but none of them are ever individually instantiated as assets. Instead they act as components to objects created within the scene. Is it possible for me to test these or do I need to change up how my code is organized?
haha I have to say, I laughed a lot watching this. This is a good way to motivate people to learn, at least I do. I am new on this channel, I like your videos. :D
Combine this with the stuff about Interfaces and it all makes so much more sense!!! You can try out new implementation or more advanced logic and then test the other simple stuff works still! It all just clicked into place
Hey how would you test sound for unit testing? Sorry new to this
Nice ~ !!
@rStarStudio
4 жыл бұрын
Nice
I’ve been a professional developer for decades, I absolutely agree that unit tests pay massive dividends over time, especially as code gets modified over time.
this would be super good if combie with Zenject
Great tutorial, thanks so much for posting this! :) I wonder what's happening when creating a new assembly reference object (the file you call Script, which you put in the folder containing all scripts). I have about 150 scripts, in different subfolder (_scripts is the main folder, from there I have sub-categories (folders) such as economy, weapons, enemies etc etc). When i follow your tutorial and create a new Assembly Definition (putting it in the main _scripts-folder, not in every subfolder (should i do that?)) I then loose the reference to all Unity-related namespaces such as animation rigging etc. It seems that this new Assembly Definition is screwing up the default implementation I assume Unity does automatically if nothing else is specified. Cheers and keep up the good work, you make awesome content!!
Hi, thanks for tutorial but i could not use testing for dotween. I keep having those "does not contain definition" errors for scripts who use dotween
Your unit test video was obsolete. This one is easy to understand & not buggy. Could you please create an example on how to create Package for Package Manager using this unit test concept. Old one is not working for me though but that was awesome.
Honestly...this guy isn't getting enough views for his quality videos, state machine was useful
4:25 to skip to relevant part
I like that anime laugh at the end :D
Big Question: How can I test an instance which gets registered and resolved by a container (VContainer e.g.)? The problem I see, is that I pass the ObjectResolver to the Ctor ...
Can u pls share your playlist with coding music, I would glad to try it out!
@IOSoraOI
4 жыл бұрын
This looks like the one: open.spotify.com/playlist/2GI6wbTjS4M4QHN8PbsIr0
@InfallibleCode
4 жыл бұрын
@@IOSoraOI That's the one!
i dont seem to get autocomplete on my test scripts when i make tests with test runner
object reference error in test cases when try to compare the gameobject position
What if I make bugs in my Unit Test code? Can I somehow test my tests? 😁
Feels like Charles is messing with your project, he knows exactly when you are in difficulty and pop in ta appear as the good guy, coincidence ? I think not. He's your evil twin. Ps: Love your video, so simple to digest, you show us a problem and slowly explain the logic to solve it.
Those two are really good friends I guess
Hey, I'd like to check your full Coding Music playlist. I've noticed you have a good taste in music :)
link to that coding music playlist please.
I like that style and all,and your tutorials come in pretty handy, because i am starting TDD and keeping it up in unity is actually pretty helpfull. But i have a error with the PlayMode Test. When i begin from ur start.example i get the error "MissingComponentException": There is no SpriteRenderer. So i tried the completed, but i still got a failed test in PlayMode. So i added a SpriteRenderer with: gameObject.AddComponent(); before the line var sheep = gameObject.AddComponent(); then it actually ran and said: eppected(0,1,0) but was(0,-1,0)
@christofstanits
2 жыл бұрын
you still need to fix the original bug in the sheep class. Line 25
Im mostly interested in that spotify coding playlist...