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

Add LoadSceneAttribute #13

Merged
merged 7 commits into from
Oct 22, 2023
Merged

Add LoadSceneAttribute #13

merged 7 commits into from
Oct 22, 2023

Conversation

nowsprinting
Copy link
Owner

@nowsprinting nowsprinting commented Oct 16, 2023

LoadSceneAttribute is an NUnit test attribute class to load scene before running test.

It has the following benefits:

  • Can be used when running play mode tests in-editor and on-player
  • Can be specified scenes that are not in "Scenes in Build"

This attribute can attached to test method only.

Usage:

using System;
using NUnit.Framework;
using TestHelper.Attributes;

[TestFixture]
public class MyTestClass
{
    [Test]
    [LoadScene("Assets/MyTests/Scenes/Scene.unity")]
    public void MyTestMethod()
    {
        var cube = GameObject.Find("Cube");
        Assert.That(cube, Is.Not.Null);
    }
}

Note

  • Load scene run after OneTimeSetUp and before SetUp
  • Scene file path is starts with Assets/ or Packages/.
    And package name using name instead of displayName, when scenes in the package.
    (e.g., Packages/com.nowsprinting.test-helper/Tests/Scenes/Scene.unity)

@github-actions github-actions bot added the enhancement New feature or request label Oct 16, 2023
@github-actions

This comment has been minimized.

@nowsprinting nowsprinting changed the title Add ScenesUsingInTest attribute Add CreateScene and LoadScene attribute Oct 22, 2023
@github-actions
Copy link

Code Metrics Report

master (d3e274e) #13 (60d35e6) +/-
Coverage 47.6% 49.5% +1.9%
Code to Test Ratio 1:0.8 1:0.8 +0.0
Test Execution Time 4m5s 4m50s +45s
Details
  |                     | master (d3e274e) | #13 (60d35e6) |  +/-  |
  |---------------------|------------------|---------------|-------|
+ | Coverage            |            47.6% |         49.5% | +1.9% |
  |   Files             |               14 |            16 |    +2 |
  |   Lines             |              330 |           404 |   +74 |
+ |   Covered           |              157 |           200 |   +43 |
+ | Code to Test Ratio  |            1:0.8 |         1:0.8 |  +0.0 |
  |   Code              |              614 |           738 |  +124 |
+ |   Test              |              487 |           609 |  +122 |
- | Test Execution Time |             4m5s |         4m50s |  +45s |

Code coverage of files in pull request scope (0.0% → 58.1%)

Files Coverage +/-
Editor/TemporaryBuildScenesUsingInTest.cs 43.6% +43.6%
Runtime/Attributes/LoadSceneAttribute.cs 100.0% +100.0%

Reported by octocov

@nowsprinting nowsprinting changed the title Add CreateScene and LoadScene attribute Add LoadScene attribute Oct 22, 2023
@nowsprinting nowsprinting merged commit d82dd8e into master Oct 22, 2023
8 checks passed
@nowsprinting nowsprinting deleted the feature/scenesusingintest branch October 22, 2023 07:46
@nowsprinting nowsprinting changed the title Add LoadScene attribute Add LoadSceneAttribute Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant