FAQ
During my testing runs I load a bunch of data with an init() function so
that all tests have it available, no matter what order the tests run in
(aside: the order in which tests run seems non-deterministics, so I figured
it had to go in an init, is there any alternative?)

For production however, I don't want to load the test data, since it is
time consuming. Is there a flag I can use inside the init() routine to
tell if I'm under a test-build or not, and then skip loading the test data
if it isn't needed?

Thanks,

Jason

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Kevin Malachowski at Dec 18, 2013 at 8:17 pm
    I'm not exactly sure if this will work, but have you looked into sync.Once? You could set up the Once either explicitly in an init or just in a package level variable and use it at the beginning of each test. That way unless a test method is called it won't run, and no matter what tests are run it will only ever run once. It may be a bit of overkill if tests are always run serially, but if they could possibly be run in parallel I think it would be a very good solution.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jimmy frasche at Dec 18, 2013 at 8:21 pm
    You could just put that init func in a _test.go file. That way it
    won't even get compiled unless you're running tests.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jason E. Aten at Dec 18, 2013 at 8:29 pm
    Ah! Move the init() to a _test.go file. Perfect. Exactly the idea I needed.
    Thanks Jimmy!

    p.s. Thanks for for the sync.Once() idea, Kevin, I'll keep that in my back
    pocket and I'm sure it will be useful in the future.
    On Wed, Dec 18, 2013 at 12:21 PM, jimmy frasche wrote:

    You could just put that init func in a _test.go file. That way it
    won't even get compiled unless you're running tests.
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Steve McCoy at Dec 18, 2013 at 8:29 pm
    If the init function is defined in a *_test.go file, it will not be
    compiled into the package. Remember that you can define inits in multiple
    files in the same package.
    On Wednesday, December 18, 2013 3:05:50 PM UTC-5, Jason E. Aten wrote:

    During my testing runs I load a bunch of data with an init() function so
    that all tests have it available, no matter what order the tests run in
    (aside: the order in which tests run seems non-deterministics, so I figured
    it had to go in an init, is there any alternative?)

    For production however, I don't want to load the test data, since it is
    time consuming. Is there a flag I can use inside the init() routine to
    tell if I'm under a test-build or not, and then skip loading the test data
    if it isn't needed?

    Thanks,

    Jason
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Matthew Kane at Dec 18, 2013 at 8:56 pm
    Wouldn't you just write a separate init() function in your *_test.go
    files? That way it is not compiled or called for your actual
    production builds.
    On Wed, Dec 18, 2013 at 3:05 PM, Jason E. Aten wrote:
    During my testing runs I load a bunch of data with an init() function so
    that all tests have it available, no matter what order the tests run in
    (aside: the order in which tests run seems non-deterministics, so I figured
    it had to go in an init, is there any alternative?)

    For production however, I don't want to load the test data, since it is time
    consuming. Is there a flag I can use inside the init() routine to tell if
    I'm under a test-build or not, and then skip loading the test data if it
    isn't needed?

    Thanks,

    Jason

    --
    You received this message because you are subscribed to the Google Groups
    "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    matt kane
    twitter: the_real_mkb / nynexrepublic
    http://hydrogenproject.com

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 18, '13 at 8:05p
activeDec 18, '13 at 8:56p
posts6
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase