Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by OtisAnderson · Apr 01, 2021 at 10:21 AM · testingnunit

In Unity3d test scripts, how to call a static function from another class?

I have two files in a Unity3d project. One of them is a test script that runs in edit mode. The other is one class with static functions that I would like to call from test scripts.

Here's my test script:

 using UnityEngine;
 using UnityEngine.TestTools;
 using NUnit.Framework;
 using System.Collections;
 
 public class NewTestScript 
 {
 
     [Test]
     public void TestAnotherStaticFunction() 
     {
         int a = NewBehaviourScript.FunctionUnderTest(1);
         int b = 1;
 
         // Use the Assert class to test conditions.
         Assert.IsTrue(a == b);
     }
 }

Here is my tested function:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class NewBehaviourScript : MonoBehaviour 
 {
     /// <summary>
     /// the stupidest function in the world, 
     /// used to verify tests.
     /// </summary>
     public static int FunctionUnderTest(int a)
     {
         return a;
     }
 }

This gives me an error from the Unity compiler (I am not building outside of Unity):

Assets / TestS / NewTestScript.cs (12,17): Error CS0103: The name `NewBehaviourScript 'does not exist in the current context

They work in edit mode.

I have tried adding and removing the SuperTestNameSpace namespace from the function under test and the calling code.

I tried to add / remove files from the .asmdef file that was auto-generated with unity, although this usually leads to other compilation errors.

My previous experience with unit testing was mostly in Visual Studio or VSCode and I am trying to write my paper so that my experience in unity3d testing matches my previous experience in testing environment.

Is there any fundamentally limited functionality in the edit mode tests, or am I missing something?

Further development of participating assemblies. It looks like there are two assemblies here: Assembly-CSharp.dll contains the code under test and TestS.dll contains the test code. I believe my questions boil down to this: How to add a reference from the TestS.dll assembly to the Assembly-CSharp.dll. I would know how to do this in Visual Studio (either through the context menu in VS, or edit the csproj file directly), however I cannot see how to do this in Unity3d. Any changes I make to the csproj file are often overwritten by one, and although there is a "links" section in the inspector (see picture), I cannot add Assembly-CSharp.dll as a link.

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

0 Replies

· Add your reply
  • Sort: 

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

157 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

Related Questions

Instantiating prefab causes assembly load error in unit test 0 Answers

Can I use LogAssert to check for errors in a unit test without cluttering the console? 0 Answers

Unable to see NUnit Assert message output 1 Answer

Unit test: PlayerPrefs, Attempted to access a missing method. 1 Answer

Testing on Genymotion: Grey Scene except Canvas items 1 Answer


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