Base solution for your next web application
Open Closed

AbpBootstrapper.Initialize() takes a long time in unit tests #444


User avatar
0
altrb created

Hi!

I was following the pattern in the CodeProject article on using Effort with Abp [http://www.codeproject.com/Articles/871786/Unit-testing-in-Csharp-using-xUnit-Entity-Framewor]) and have it all working and some 100 green unit tests. The problem is though that the test suite now takes a long time to run. I did some profiling on my code and found that the bulk of the time is spent in the AbpBootstrapper.Initialize() code

var bootstrapper = new AbpBootstrapper(LocalIocManager);
            bootstrapper.Initialize();

Since the environment is re-created for each UT, and the init time takes 0.4 seconds, my suite that recently took some 13 seconds now take more like 45. Seems to me the reason is that each UT now causes all modules to be loaded and initialized including the standard call to

IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

...a lot of disk access which adds up. Might be other things too.

Any ideas on how to speed up things?


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    In this article, actually we're doing "Integration Test", not "Unit Test". And by it's nature, Integration Tests are slower. But it's very easier to write as you see. You don't have to mock, all just works. If you want to write unit tests, you should get a class and mock all dependencies. And don't inherit from AbpIntegratedTestBase class. This will be very fast but harder to write. So, it's a tradeoff.

  • User Avatar
    0
    guillaumej created

    It's an old post, but I'm also discovering that even a very basic test is taking 1 second (on my computer, 5 on visual studio.com)

    This is awfully slow for just testing a simple, rounding method (I'm just calling Math.Round, in fact)

    There's no call sto ABP, Services, Context, anything, except in the constructor/ initialize.

    I think the problem is due to XUnit, since it create a new test class instance for every test methods, all ABP pipeline/init must be started anew, so, it's too slow.

    I'm going to rewrite my tests using MS Test, using LocalDb (1) to create a test DB, and using transactions to keep it clean

    (1) Effort is supposed to be faster, but I have two problems with it :

    • it does not support Database.SqlQuery
    • I can't not check the SQL generated by Linq when I'm using it.