Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by Domihansa · Apr 29, 2019 at 07:13 PM · referenceassemblytestrunnerdefinition

Unity Test Runner --> unable to reference my code from the test

Hi @ll,

I have a Unity 2018.3.12/C# project called Assembly-CSharp using VS 2017 as IDE.

I want to create a test which I can call from the Unity Test Runner.

When I create the test, the code there is unable to reference the code in my main project.

For this problem, there are some suggestions on the internet here https://answers.unity.com/questions/1540387/missing-reference-between-assembly-csharp-and-test.html and here https://stackoverflow.com/questions/53845650/in-unity3d-test-scripts-how-do-i-call-a-static-function-from-another-class.

There, I am told to create an assembly definition on the top of my code (folder Assets/scripts) and reference this assembly definition from the Tests.asmdef. Problem: When I create such an assembly definition, Visual Studio creates an entirely new project from only the code files and extracts my code files from my actual project "Assembly-CSharp". This leads to numerous other compile errors. Alternative: I created a Reference from the "Tests" project (containing the Unity tests) to the "Assembly-CSharp" project in VISUAL STUDIO. Unfortunately, Unity doesn't want me to do that and kills this reference every time I start the editor.

So basically, I am only trying to create a Unity Test referencing my code which I can run with the Test Runner and it just doesn't work! Can anyone help me?

Thank you, Domihansa

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Domihansa · May 07, 2019 at 09:20 AM

Hi, thanks for the answer. I got it to work with the asmdef version of the tests, simply by putting the assembly definition "NewAssembly.asmdef" one layer ahead in the folder hierarchy: I put it in the folder "Assets" instead of "Assets/scripts". Now, Visual Studio still creates a new project from that, but in Visual Studio, it just replaces the "Assembly-C-Sharp" project by the "NewAssembly" project and tests as well as game work fine. Maybe not the most proper solution, but it works now.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by HaraldNielsen · Apr 30, 2019 at 07:13 AM

Hi, There are two ways to have tests in your project:

  • Using asmdef's. This will indeed create a new project because that code will be in a separate Assembly. This way there is a clear separation of your tests and your game code. There should be good guidence how to do it here https://docs.unity3d.com/Manual/testing-editortestsrunner.html

  • Enable tests for everything. This setting was added before asmdef's got into the world. This will then add references to nunit and the TestRunner assemblies. The downside here is that your test code can be included in your final player builds and increase the size.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't reference other namespaces from within TextMeshPro (TMPro) namespace. 0 Answers

Test runner errors InvalidOperationException and TreeView root item is null 1 Answer

Error CS1061 type Valve.VR.SteamVR_Render - Got code from another project? 0 Answers

Visual studio cannot find references to dlls from custom assembly definitions 2 Answers

Unity and external plugins 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges