I am running a rake task for the more number of operations.
Eg: rake test:sample
Finished in 66.951185957 seconds.
1 tests, 256 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
0.01 tests/s, 3.82 assertions/s
I want to store the overall final result of rake task such as number of tests passed/failed with file name, assertions,errors etc in a file like index.html will be generated for rspec tests in coverage/index.html. I am using Test::Unit in rake task.
Can any one tell me solution for it.
You should have a look at the rspec's help rspec --help which gives you a lot of options when testing with rspec. Hope it helps.
We can use ci_reporter gem to generate the reports. it will results in xml format.
Link Here
Related
I'm trying to get this:
http://www.amazon.com/Dream-Cheeky-902-Electronic-Reference/dp/B004D18MCK
working on a mac using this:
https://github.com/derrick/dream_cheeky
After running rake, it says "4 examples, 0 failures, 2 pending". How do I execute the actual ruby example that I want? (I'm a Ruby noob)
Thanks!
4 examples, 0 failures, 2 pending is a message from RSpec saying there are two unit tests that are pending.
A pending test is generally a test that the author hasn't fully implemented yet. You can think of it like a function that you stubbed out to finish later. For example:
def add_two_numbers(n1, n2)
# TODO write some code that adds n1 and n2
end
As the comments mention, a pending test won't stop you from using the library successful.
Here is an example of pending:
https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/pending/pending-examples
I started along the process of trying to speed up my tests, mostly by following this railscast's suggestions. So you don't have to watch it, those are:
Replaced "bundle exec spec" with "bin/rspec spec"
Got rid of excess before filters
Tagged slow tests as such for separate running
Replaced unnecessary Factory Creates with Builds
Used Zeus to speed up start-up time
Applied VCR to examples that reached out to external APIs
Deferred Garbage Collection
(I skipped parallel testing for now, cause I want to get to the bottom of this issue, and parallel testing seems like it would just minimize/mask it)
At any rate, I can't figure out whether these changes have accomplished much, because the runtimes for my tests are highly variable. (They are variable even when I go outside of the branch I've been working on for these tests -- seems like something preexisting is causing the problem). I've run the exact same suite of tests now and gotten a wide range of runtimes, from 52 seconds to almost 1m45! Again, the EXACT same tests.
Moreover, the general trend seems to be that if I run a test a few times in a row, the runtimes go up by ~20 second intervals each time. Then if I change something small in spec_helper or wait for a while (I think the latter -- I know this has happened when I've made small changes to garbage collection), the times go back down.
My guess is that this problem is related to garbage collection -- but ideally, I'm doing that more efficiently now. I had it collect garbage every ~15 seconds,
spec_helper.rb
config.before(:all) { DeferredGarbageCollection.start }
config.after(:all) { DeferredGarbageCollection.reconsider }
support/deferred_garbage_collection.rb
class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || 15.0).to_f
##last_gc_run = Time.now
def self.start
GC.disable if DEFERRED_GC_THRESHOLD > 0
end
def self.reconsider
if DEFERRED_GC_THRESHOLD > 0 && Time.now - ##last_gc_run >= DEFERRED_GC_THRESHOLD
GC.enable
GC.start
GC.disable
##last_gc_run = Time.now
end
end
end
and then, when that was causing the aforementioned problems, I switched to a more straightforward every-ten-test collection system:
spec_helper.rb
config.after(:each) do
counter += 1
if counter > 9
GC.enable
GC.start
GC.disable
counter = 0
end
end
config.after(:suite) do
counter = 0
end
I've tried to isolate this to a group of tests (models/requests/controllers), but they all seem to display some amount of variability in relation to roughly how much time they eat up.
Any ideas what's going wrong here?
EDIT -- proof/example of what's going on here:
Finished in 22.88 seconds
48 examples, 0 failures
➜ my_app git:(faster-tests) ✗>zeus test spec/models
................................................
Finished in 34.89 seconds
48 examples, 0 failures
➜ my_app git:(faster-tests) ✗>zeus test spec/models
................................................
Finished in 44.68 seconds
48 examples, 0 failures
➜ my_app git:(faster-tests) ✗>zeus test spec/models
................................................
Finished in 14.36 seconds
48 examples, 0 failures
➜ my_app git:(faster-tests) ✗>zeus test spec/models
................................................
Finished in 18.74 seconds
48 examples, 0 failures
➜ my_app git:(faster-tests) ✗>
Note that it eventually seems to reset.
I'm not sure about all the other things you have done but I can comment on zeus. I did not alter anything in my environment except add zeus and I can run 50 examples in a couple of seconds. For tests to take as long as yours when running zeus seems wrong and I'm guessing thats your problem. After you run zeus start are all the zeus commands green? I also use zeus rspec spec/.... to run my specs instead of zeus test.
I used this railscast and this thoughtbot article along with the zeus README. Remeber to use the appropriate Ruby version mentioned in the railscast and make sure that you dont have spork anymore if you were using spork. Also remember to install zeus outside of your Gemfile, zeus should not use Bundler. Anyway, my suggestion would be to focus on zeus first and get that working correctly. It has really helped for me
For some reason, RSpec is not recognizing assertions in one of my spec files - but runs the print statement around it.
To start the spec test, on the terminal:
rspec spec/lib/slots_scheduler_spec.rb
Part of the spec file that asserts... (is part of a loop)
print "#{slots_result[0].date} #{slot.date}\n"
slots_result[0].date.should == slot.date
And what I see on the console...
....
2012-11-18 2012-11-11
2012-11-25 2012-11-11
No examples found.
Finished in 0.00005 seconds
0 examples, 0 failures
If something is wrong, I expect some other message than '0 examples, 0 failures'. Why are my tests ignored like this?
You Haven't Defined an Example Group
Your code, as posted above, has no example groups. Example groups require a describe or context block, and a specify or it block for each test in order to work.
Your print statements work because they are valid Ruby. However, the RSpec DSL requires more from you before it will result in an actual test being performed.
When running unit and functional tests using rake, on a rails application, I notice that there is a seed value which is specified on the command line: --seed x
$ rake test
(in /code/blah)
Loaded suite /../ruby-1.9.2-p180/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.
Finished in 0.12345 seconds.
1 tests, 1 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 20290
I assume it is possible to use this value in the tests, but I can't figure out how.
I've tried Google, Rails Guides et al. but can't seem to find the answer.
EDIT:
Could this seed value be the option that is used by Minitest to randomize the execution order of tests?
I found this online about MiniTest: http://www.mikeperham.com/2012/09/25/minitest-ruby-1-9s-test-framework/
Turns out, you are right. It is about randomizing the execution order of tests. You can explicitly use them like this:
rake TESTOPTS="--seed=1261"
(according to the above link).
The answer from MrDanA is correct. This solution also works and is slightly shorter and easier to remember.
SEED=20290 rake test
How do I get line numbers to be reported with my errors when testing. Here is what I get back on a typical error:
josh#josh-laptop:~/d/test$ ruby unit/line_test.rb -n test_update
Loaded suite unit/line_test
Started
E
Finished in 0.066663 seconds.
1) Error:
test_update(LineTest):
NameError: undefined local variable or method `sdf' for
#<LineTest:0xb6e61304>
1 tests, 0 assertions, 0 failures, 1 errors
It is tough to debug without a line number and filename. From the code
samples I've seen, people generally get back a more verbose error
reports. How do I enable this?
Thanks!
[Edit] From the Rails Guide
$ ruby unit/post_test.rb -n test_should_report_error
Loaded suite -e
Started
E
Finished in 0.082603 seconds.
1) Error:
test_should_report_error(PostTest):
NameError: undefined local variable or method `some_undefined_variable' for #<PostTest:0x249d354>
/test/unit/post_test.rb:6:in `test_should_report_error'
1 tests, 0 assertions, 0 failures, 1 errors
How long are your unit tests? Typically, a test case should only be a couple of lines of code. If not, consider splitting it up. That should really narrow it down, particularly for an undefined variable or method. In any case, if you install ruby-debug, you can step through the test case and see exactly where the problem lies.
I found an answer that I don't like but which gets the job done. I thought I'd post it in case others can't find a better solution
ruby -d unit/line_test.rb -n test_update
-d sets the $DEBUG to true and gives a dump with error, warning, exception details
If this is a Rails app? Then most likely Rails' backtrace cleaner is getting in the way. Most likely because your directory starts with "unit" not "test" like Rails assumes. I ran into a similar issue (a plugin I was developing was outside the Rails directory so the entire backtrace was being filtered).
Check out the default silencer and either add a filter so that it will pass this silencer (filters run before silencers) OR simply remove the silencer with remove_silencers!. Rails provides a file in the initializers directory that will do this but the line is commented out by default.