- Home /
TextAsset connected for app but not for TestRunner
In my JsonReader.cs script, I have the following: // file to read lessons from public TextAsset jsonFile;
In the Unity editor, I have created a file: Assets/Resources/lesson-test.json, and dragged it to the jsonFile field of the script.
In my app, the following works fine: // file to read lessons from public TextAsset jsonFile;
void Start()
{
Assert.IsNotNull(jsonFile);
}
but from Test Runner, this fails:
[UnityTest]
public IEnumerator TestStart()
{
Assert.Pass();
yield return null;
}
TestStart (0.023s)
---
Unhandled log message: '[Exception] AssertionException: Assertion failure. Value was Null
Expected: Value was not Null'. Use UnityEngine.TestTools.LogAssert.Expect
---
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <f38c71c86aa64e299d4cea9fb7c715e1>:0)
UnityEngine.Assertions.Assert.IsNotNull (UnityEngine.Object value, System.String message) (at <f38c71c86aa64e299d4cea9fb7c715e1>:0)
UnityEngine.Assertions.Assert.IsNotNull[T] (T value, System.String message) (at <f38c71c86aa64e299d4cea9fb7c715e1>:0)
UnityEngine.Assertions.Assert.IsNotNull[T] (T value) (at <f38c71c86aa64e299d4cea9fb7c715e1>:0)
JsonReader.Start () (at Assets/Scripts/JsonReader.cs:41)
---
AssertionException: Assertion failure. Value was Null
Expected: Value was not Null
How do I make this TextAsset connect properly when running TestRunner?
Answer by tmurraysdca70 · May 06, 2020 at 09:30 PM
I can't figure out how to edit my post, this should have been in a code block: // file to read lessons from public TextAsset jsonFile;
I figured it out:
I figured it out:
[SetUp]
public void Setup()
{
jsonReader = new GameObject().AddComponent<JsonReader>();
jsonReader.jsonFile = Resources.Load("lesson-test") as TextAsset;
}
// Verify class exists
[Test]
public void JsonReaderClassExists()
{
Assert.IsNotNull(jsonReader);
Assert.IsNotNull(jsonReader.jsonFile);
}
Your answer
Follow this Question
Related Questions
how to find if WWW Post Request is succesful? 2 Answers
WWW.text string not correct? 2 Answers
converting excel to json: reading problem when file too large 0 Answers
Getting data out of Dictionary 0 Answers
Accessing a Json FILE and using it to set variables 2 Answers