top_tests 0.0.3 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +6 -1
- data/README.rdoc +27 -5
- data/lib/minitest/top_tests_plugin.rb +60 -0
- data/lib/top_tests.rb +22 -11
- data/lib/top_tests/version.rb +1 -3
- data/test/failing_test.rb +10 -0
- data/test/fast_test.rb +10 -0
- data/test/slow_test.rb +14 -0
- data/top_tests.gemspec +4 -4
- metadata +16 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2ee9095ac592d144455ac280f91819b3fa0886148f41af4f5c02b4e031ab6256
|
4
|
+
data.tar.gz: 9e3f02ba897f988c2f7868010368a4deb697ba2a2a218e077815174be4d727f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 44724156a8d2fdc6a6991121f07d3a93b2f3146e56ea35af9773e28105a7f3fb891f2baf9393a7329359f36e896a5d42c882f930ce7c9a3430195186a086f204
|
7
|
+
data.tar.gz: f6a5daaeff5d68d0b35f469ce89381d454e47b87044b5478a9b228c15208d8e86c928429499253098188157a933c6639428c3c41afec4b75f298e1521ecb9434
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
top_tests (0.0.
|
4
|
+
top_tests (0.0.6)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: http://rubygems.org/
|
8
8
|
specs:
|
9
|
+
minitest (5.10.2)
|
9
10
|
|
10
11
|
PLATFORMS
|
11
12
|
ruby
|
12
13
|
|
13
14
|
DEPENDENCIES
|
15
|
+
minitest (>= 5.10.2)
|
14
16
|
top_tests!
|
17
|
+
|
18
|
+
BUNDLED WITH
|
19
|
+
1.13.6
|
data/README.rdoc
CHANGED
@@ -2,11 +2,33 @@
|
|
2
2
|
Top tests displays your 10 slowest tests after execution. The goal is to help you
|
3
3
|
keeping your tests fast.
|
4
4
|
|
5
|
-
|
6
|
-
First of all top tests works only with ActiveSupport::TestCase. Then require top
|
7
|
-
tests and just include into your test class:
|
5
|
+
Moreover top tests can break your build if any test is taking longer than a specified duration.
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
== How to use it?
|
8
|
+
Add to your Gemfile.
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem 'top_tests'
|
11
12
|
end
|
12
13
|
|
14
|
+
Then run your test as usual and you will have a similar output:
|
15
|
+
|
16
|
+
Top 10 slowest tests:
|
17
|
+
0.429 ApplicationControllerTest#test_notify_error
|
18
|
+
0.322 HoneyBadgersControllerTest#test_show
|
19
|
+
0.200 BearsControllerTest#test_destroy_collection
|
20
|
+
0.134 SuricatsControllerTest#test_can_not_update
|
21
|
+
0.124 SuricatsControllerTest#test_create
|
22
|
+
0.105 SuricatsControllerTest#test_update
|
23
|
+
0.096 HoneyBadgersControllerTest#test_create
|
24
|
+
0.093 HoneyBadgersControllerTest#test_update
|
25
|
+
0.091 SuricatsControllerTest#test_destroy
|
26
|
+
0.090 HoneyBadgersControllerTest#test_show
|
27
|
+
|
28
|
+
Run your your with the option `--max-time=SECONDS` to break the tests that are slower than the specified time:
|
29
|
+
|
30
|
+
3 tests are taking longer than 0.2 seconds:
|
31
|
+
0.410 HoneyBadgerTest#test_fighting_a_cobra
|
32
|
+
0.228 SuricatTest#test_caught_by_an_eagle
|
33
|
+
0.203 HoneyBadgerTest#test_eating_larvae
|
34
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Minitest
|
2
|
+
def self.plugin_top_tests_init(options)
|
3
|
+
self.reporter << TopTestReporter.new(options)
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.plugin_top_tests_options(opts, options)
|
7
|
+
opts.on "--max-time=ms", "Test fails if it exceeds specified time in seconds" do |max_time|
|
8
|
+
options[:max_time] = max_time.to_f
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class TopTestReporter < AbstractReporter
|
13
|
+
attr_reader :results, :max_time
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
@results = []
|
17
|
+
@max_time = options[:max_time]
|
18
|
+
end
|
19
|
+
|
20
|
+
def record(result)
|
21
|
+
results << result
|
22
|
+
#result.refute(true, "Too long") if max_time && result.time > max_time
|
23
|
+
end
|
24
|
+
|
25
|
+
def passed?
|
26
|
+
slow_tests.empty?
|
27
|
+
end
|
28
|
+
|
29
|
+
def report
|
30
|
+
if slow_tests.empty?
|
31
|
+
puts "\nTop 10 slowest tests:\n#{format_tests(slowest_results[0,10])}"
|
32
|
+
else
|
33
|
+
print_slow_tests
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def slowest_results
|
38
|
+
results.sort { |a, b| b.time <=> a.time }
|
39
|
+
end
|
40
|
+
|
41
|
+
def slow_tests
|
42
|
+
max_time ? results.find_all { |r| r.time > max_time } : []
|
43
|
+
end
|
44
|
+
|
45
|
+
def print_slow_tests
|
46
|
+
if !slow_tests.empty?
|
47
|
+
if slow_tests.size == 1
|
48
|
+
puts "\n1 test is taking longer than #{max_time} seconds:"
|
49
|
+
else
|
50
|
+
puts "\n3 tests are taking longer than #{max_time} seconds:"
|
51
|
+
end
|
52
|
+
puts format_tests(slow_tests)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def format_tests(tests)
|
57
|
+
tests.map { |t| " #{format("%7.3f", t.time)} #{t.klass}##{t.name}" }.join("\n")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/top_tests.rb
CHANGED
@@ -7,23 +7,30 @@ module TopTests
|
|
7
7
|
#####################
|
8
8
|
|
9
9
|
def self.included(klass)
|
10
|
-
klass.setup :start_timer
|
11
|
-
klass.teardown :stop_timer
|
12
10
|
klass.extend(ClassMethods)
|
13
|
-
|
11
|
+
if Minitest.respond_to?(:after_run)
|
12
|
+
Minitest.after_run { klass.after_all_tests }
|
13
|
+
else
|
14
|
+
MiniTest::Unit.after_tests { klass.after_all_tests } # Deprecated
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
########################
|
17
19
|
### Instance methods ###
|
18
20
|
########################
|
19
21
|
|
20
|
-
def
|
22
|
+
def before_setup
|
23
|
+
super
|
21
24
|
@timer_started_at = Time.now
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
+
def after_teardown
|
28
|
+
super
|
29
|
+
if @timer_started_at # Unset when a setup hook fails before top test.
|
30
|
+
# Instance variable @__name__ is used prior to minitest 5.
|
31
|
+
test_name = "#{self.class}##{@__name__ || name}"
|
32
|
+
self.class.tests_durations << [test_name, Time.now - @timer_started_at]
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
#####################
|
@@ -40,7 +47,7 @@ module TopTests
|
|
40
47
|
end
|
41
48
|
|
42
49
|
def max_duration
|
43
|
-
@@max_duration
|
50
|
+
@@max_duration ||= nil
|
44
51
|
end
|
45
52
|
|
46
53
|
def top_tests
|
@@ -56,21 +63,25 @@ module TopTests
|
|
56
63
|
end
|
57
64
|
|
58
65
|
def print_top_tests
|
59
|
-
puts "\nTop tests:"
|
66
|
+
puts "\nTop 10 slowest tests:"
|
60
67
|
puts format_tests(top_tests.shift(10))
|
61
68
|
puts
|
62
69
|
end
|
63
70
|
|
64
71
|
def check_tests_duration
|
65
72
|
if !slow_tests.empty?
|
66
|
-
|
73
|
+
if slow_tests.size == 1
|
74
|
+
puts "\nTEST?FAIL! 1 test is taking longer than #{max_duration} seconds:"
|
75
|
+
else
|
76
|
+
puts "\nTEST?FAIL! #{slow_tests.count} tests are taking longer than #{max_duration} seconds:"
|
77
|
+
end
|
67
78
|
puts format_tests(slow_tests)
|
68
79
|
puts
|
69
80
|
exit 1
|
70
81
|
end
|
71
82
|
end
|
72
83
|
|
73
|
-
def
|
84
|
+
def after_all_tests
|
74
85
|
check_tests_duration
|
75
86
|
print_top_tests
|
76
87
|
end
|
data/lib/top_tests/version.rb
CHANGED
data/test/fast_test.rb
ADDED
data/test/slow_test.rb
ADDED
data/top_tests.gemspec
CHANGED
@@ -6,10 +6,10 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.name = 'top_tests'
|
7
7
|
s.version = TopTests::VERSION.dup
|
8
8
|
s.authors = ['Alexis Bernard']
|
9
|
-
s.email = ['alexis@
|
10
|
-
s.homepage = 'https://github.com/
|
11
|
-
s.summary = 'Top tests
|
12
|
-
s.description = 'Top tests
|
9
|
+
s.email = ['alexis@bernard.io']
|
10
|
+
s.homepage = 'https://github.com/alexisbernard/top_tests'
|
11
|
+
s.summary = 'Top tests lists the 10 slowest tests after execution'
|
12
|
+
s.description = 'Top tests lists the 10 slowest tests after execution'
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,54 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: top_tests
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Alexis Bernard
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description: Top tests
|
13
|
+
description: Top tests lists the 10 slowest tests after execution
|
15
14
|
email:
|
16
|
-
- alexis@
|
15
|
+
- alexis@bernard.io
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
|
-
- .gitignore
|
20
|
+
- ".gitignore"
|
22
21
|
- Gemfile
|
23
22
|
- Gemfile.lock
|
24
23
|
- LICENSE
|
25
24
|
- README.rdoc
|
26
25
|
- Rakefile
|
26
|
+
- lib/minitest/top_tests_plugin.rb
|
27
27
|
- lib/top_tests.rb
|
28
28
|
- lib/top_tests/version.rb
|
29
|
+
- test/failing_test.rb
|
30
|
+
- test/fast_test.rb
|
31
|
+
- test/slow_test.rb
|
29
32
|
- top_tests.gemspec
|
30
|
-
homepage: https://github.com/
|
33
|
+
homepage: https://github.com/alexisbernard/top_tests
|
31
34
|
licenses: []
|
35
|
+
metadata: {}
|
32
36
|
post_install_message:
|
33
37
|
rdoc_options: []
|
34
38
|
require_paths:
|
35
39
|
- lib
|
36
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
-
none: false
|
38
41
|
requirements:
|
39
|
-
- -
|
42
|
+
- - ">="
|
40
43
|
- !ruby/object:Gem::Version
|
41
44
|
version: '0'
|
42
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
46
|
requirements:
|
45
|
-
- -
|
47
|
+
- - ">="
|
46
48
|
- !ruby/object:Gem::Version
|
47
49
|
version: '0'
|
48
50
|
requirements: []
|
49
|
-
|
50
|
-
rubygems_version: 1.8.10
|
51
|
+
rubygems_version: 3.0.3
|
51
52
|
signing_key:
|
52
|
-
specification_version:
|
53
|
-
summary: Top tests
|
53
|
+
specification_version: 4
|
54
|
+
summary: Top tests lists the 10 slowest tests after execution
|
54
55
|
test_files: []
|