question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make it possible to create unit tests for Actors

See original GitHub issue

Right now i can’t create a actor inside a unit test. Take the following Actor code for example

public class TestActor : Actor
{
    public TestActor(ActorService actorService, ActorId actorId) : base(actorService, actorId)
    {
    }

    public async Task<string> GetString()
    {
        return await StateManager.GetStateAsync<string>("Test");
    }
}

And using the following unit test:

    [Test]
    public async Task CanCreateActor()
    {
        var actor = new TestActor(
            new ActorService(
                new ActorTypeInformation()
            ),
            new ActorId("Test")
        );

        Assert.IsInstanceOf<Actor>(actor);
    }

When i run the unit test it throws a NullRefference exception

Message: 
    System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace: 
    Actor.ctor(ActorService actorService, ActorId actorId)
    TestActor.ctor(ActorService actorService, ActorId actorId) line 12
    IAMEmployeeTest.CanCreateActor() line 19
    GenericAdapter`1.GetResult()
    AsyncToSyncAdapter.Await(Func`1 invoke)
    TestMethodCommand.RunTestMethod(TestExecutionContext context)
    TestMethodCommand.Execute(TestExecutionContext context)
    SimpleWorkItem.PerformWork()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
amanbhacommented, Feb 14, 2020

Keeping this open for tracking more improvements to making actor unit tests

2reactions
amanbhacommented, Feb 12, 2020

@malotho I would suggest to keep it open to track more improvements needed in SDK itself to make it easier to write unit tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to unit-test an actor that gets a reference to another ...
Inject an ActorProxyFactory into the calling Actor constructor, and use that to create ActoryProxy instances. Like shown here or here.
Read more >
Writing tests for actors — Leapp 0.15.1 documentation
Tests are considered being part of the actor and we do not only encourage but basically require you to write tests if you...
Read more >
Chapter 3. Test-driven development with actors - Akka in Action
The test kit provides a TestActorRef that allows access to the underlying actor instance. This makes it possible to test the actor instance...
Read more >
Unit Tests with Actor Framework - NI Community
I use the JKI VI Tester to unit test my actors. I test the public interface. I use the init methods in the...
Read more >
Testing Classic Actors - Documentation - Akka
The actor model presents a different view on how units of code are delimited and how they interact, which influences how to perform...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found