# Outer constructor in testset

**URL:** <https://discourse.julialang.org/t/outer-constructor-in-testset/25318>\
**Category:** New to Julia\
**Tags:** testing\
**Created:** [June 14, 2019, 6:22pm UTC](https://discourse.julialang.org/t/outer-constructor-in-testset/25318 "2019-06-14T18:22:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [June 14, 2019, 6:22pm UTC](https://discourse.julialang.org/t/outer-constructor-in-testset/25318/1 "2019-06-14T18:22:51Z")

</div>

Hi,

I’m having some trouble using structs inside @testsets:

```julia
julia> @testset "teststruct" begin
       struct a end
       a(b) = a()
       end
teststruct: Error During Test at none:1
  Got exception outside of a @test
  syntax: Slot objects should not occur in an AST
  Stacktrace:
   [1] top-level scope at none:2
   [2] top-level scope at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\Test\src\Test.jl:1083
   [3] top-level scope at none:2
   [4] eval at .\boot.jl:328 [inlined]
   [5] repleval(::Module, ::Expr) at E:\Programs\julia\.julia\packages\Atom\E4PBh\src\repl.jl:135
   [6] (::getfield(Atom, Symbol("##168#170")){Module})() at E:\Programs\julia\.julia\packages\Atom\E4PBh\src\repl.jl:157
   [7] with_logstate(::getfield(Atom, Symbol("##168#170")){Module}, ::Base.CoreLogging.LogState) at .\logging.jl:395
   [8] with_logger at .\logging.jl:491 [inlined]
   [9] evalrepl(::Module, ::String) at E:\Programs\julia\.julia\packages\Atom\E4PBh\src\repl.jl:148
   [10] top-level scope at E:\Programs\julia\.julia\packages\Atom\E4PBh\src\repl.jl:190
   [11] eval(::Module, ::Any) at .\boot.jl:328
   [12] eval_user_input(::Any, ::REPL.REPLBackend) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.1\REPL\src\REPL.jl:85
   [13] run_backend(::REPL.REPLBackend) at E:\Programs\julia\.julia\packages\Revise\UtBAC\src\Revise.jl:943
   [14] (::getfield(Revise, Symbol("##74#76")){REPL.REPLBackend})() at .\task.jl:259Test Summary: | Error Total
teststruct | 1 1
ERROR: Some tests did not pass: 0 passed, 0 failed, 1 errored, 0 broken.

```

Am I doing something wrong?

Inner constructors seem to work:

```julia
julia> @testset "teststruct" begin
       struct a
       a(b) = new()
       end
       end
Test Summary: |
teststruct | No tests
Test.DefaultTestSet("teststruct", Any[], 0, false)

```

It also works if I put the code at the top of a file which is included from runtests.jl, even if the file is included inside a @testset in runtests.jl which in many cases is far from ideal.

I just discovered that it works with inner constructors so if there are any major drawbacks with that approach I guess I’ve yet to discover them 🙂

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 14, 2019, 6:42pm UTC](https://discourse.julialang.org/t/outer-constructor-in-testset/25318/2 "2019-06-14T18:42:03Z")

</div>

This looks like a bug, I opened an issue: [https://github.com/JuliaLang/julia/issues/32325](https://github.com/JuliaLang/julia/issues/32325).
