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

[USDU-249] Adds test case for InitUSD #330

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions package/com.unity.formats.usd/Tests/Editor/InitUsdTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.IO;
using NUnit.Framework;
using System.Reflection;
using Unity.Formats.USD;

public class InitUsdTests
{
[Test]
[Ignore("[USDU-249]")]
public void SetupUsdPath_InvalidPath_Error()
{
// SetupUsdPath function is a private function
var setUpMethod = GetMethod("SetupUsdPath");

try
{
setUpMethod.Invoke(null, new object[] { "\\NonExisting\\Path\\" });
}
catch (TargetInvocationException e)
{
Assert.AreEqual(e.InnerException.GetType(), typeof(FileNotFoundException));
lee-aandrew marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Assert.Fail("Exception was expected but none was thrown");
}

[Test]
public void SetupUsdPath_EmptyPath_Error()
{
// SetupUsdPath function is a private function
var setUpMethod = GetMethod("SetupUsdPath");

try
{
setUpMethod.Invoke(null, new object[] { "" });
}
catch (TargetInvocationException e)
{
Assert.AreEqual(e.InnerException.GetType(), typeof(System.ArgumentException));
return;
}

Assert.Fail("Exception was expected but none was thrown");
}

[Test]
public void InitUsd_Initialize()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the expected result to the end of the test name, something like "InitUsd_Initialize_Succeeds"

{
// Reset 'm_usdInitialized' for accurate testing
ResetInitUsd();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that just changing the bool is enough here. Initialize() does stuff that might affect this test, such as setting up the UnityTypeBindings for USD. I'm not sure what the answer is though :D


Assert.True(InitUsd.Initialize());
}

[TearDown]
public void ResetInitUsd()
{
var isUsdInitialized = typeof(InitUsd).GetField("m_usdInitialized", (BindingFlags.Static | BindingFlags.NonPublic));
isUsdInitialized.SetValue(null, false);
}

private MethodInfo GetMethod(string methodName)
{
var method = typeof(InitUsd).GetMethod(methodName, (BindingFlags.NonPublic | BindingFlags.Static));

if (method == null)
{
Assert.Fail(string.Format("{0} method not found", methodName));
}

return method;
}
}
11 changes: 11 additions & 0 deletions package/com.unity.formats.usd/Tests/Editor/InitUsdTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.