Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing and static object issues #35

Closed
a-ivanov opened this issue Sep 23, 2019 · 5 comments
Closed

Unit testing and static object issues #35

a-ivanov opened this issue Sep 23, 2019 · 5 comments

Comments

@a-ivanov
Copy link

Project doesn't have any unit tests. There are numerous well-known benefits with them. Unity has NUnit integration with specific Play mode.

When I tried to implement a test I found it difficult due to global static variables and singletons couplings.

Example: test Ped.SpawnPed(int, Transform). It calls Item.GetDefinition(int) which searches a static Dictionary for preloaded PedestrianDef.

Such things prevent mocking (e.g. with Moq).

There are alternatives to singletons like Service Locator pattern (a simple Dependency Injection) which is employed in other projects. It is not perfect but in contrast to singletons it allows us to write quality tests with mocks and decouples concrete service implementations.

What do you think of gradual migration to such components structure?

@in0finite
Copy link
Owner

I am aware of benefits of unit testing. But there are many singletons in the project, and migrating to other solutions would require a lot of work. So, my opinion is that one should focus on implementing features/fixing bugs, rather than on making tests.

@slapin
Copy link

slapin commented Sep 24, 2019 via email

@a-ivanov
Copy link
Author

To tell you the truth, I have started working on this. The project is a promising one and fun, but also a big one. The code quality is gonna degrade without testing.

It also reveals code smells which translate to bugs and a lack of inner mechanics understanding by others.

@a-ivanov
Copy link
Author

The main problem with testing now is that all game objects and usual C# classes are interconnected via static singleton / functions. It is not practical (and maybe impossible sometimes) to test such code.

The first thing to do is to find a way to decouple dependencies in order to substitute them in tests. As long as Unity creates game objects this is a tricky business but there are ways I'm trying to do / researching now.

@in0finite
Copy link
Owner

I wouldn't like to dissapoint you. But my opinion is that tests are not neccesary at this moment. We should focus on high priority stuff. Doing what you want requires changing core parts of the game, which can cause a lot of bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants