Testing configurable resources
You can test the initialization of a ConfigurableResource by constructing it manually. In most cases, the resource can be constructed directly:
    import dagster as dg
    class MyResource(dg.ConfigurableResource):
        value: str
        def get_value(self) -> str:
            return self.value
    def test_my_resource():
        assert MyResource(value="foo").get_value() == "foo"
If the resource requires other resources, you can pass them as constructor arguments:
    import dagster as dg
    class StringHolderResource(dg.ConfigurableResource):
        value: str
    class MyResourceRequiresAnother(dg.ConfigurableResource):
        foo: StringHolderResource
        bar: str
    def test_my_resource_with_nesting():
        string_holder = StringHolderResource(value="foo")
        resource = MyResourceRequiresAnother(foo=string_holder, bar="bar")
        assert resource.foo.value == "foo"
        assert resource.bar == "bar"
Testing with resource context
In the case that a resource uses the resource initialization context, you can use the build_init_resource_context utility alongside the with_init_resource_context helper on the resource class:
    import dagster as dg
    from typing import Optional
    class MyContextResource(dg.ConfigurableResource[GitHub]):
        base_path: Optional[str] = None
        def effective_base_path(self) -> str:
            if self.base_path:
                return self.base_path
            instance = self.get_resource_context().instance
            assert instance
            return instance.storage_directory()
    def test_my_context_resource():
        with dg.DagsterInstance.ephemeral() as instance:
            context = dg.build_init_resource_context(instance=instance)
            assert (
                MyContextResource(base_path=None)
                .with_resource_context(context)
                .effective_base_path()
                == instance.storage_directory()
            )