Skip to content

Commit

Permalink
Merge cd1e61c into 9191a19
Browse files Browse the repository at this point in the history
  • Loading branch information
ldjebran committed Apr 13, 2018
2 parents 9191a19 + cd1e61c commit 46ed950
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LineLength:
Max: 119

MethodLength:
Max: 20
Max: 40

ClassLength:
Max: 200
Expand Down
73 changes: 64 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,49 @@ Note: only tests with pid attribute set will be reported

.. code-block:: bash
$ bundle exec rake minitest test
$ bundle exec rake minitest test TESTOPTS=-v --trace
This will generate one file at test/reports/robottelo-results.xml with content
Console output:

.. code-block:: bash
** Invoke minitest (first_time)
** Invoke robottelo:setup:minitest (first_time)
** Execute robottelo:setup:minitest
** Execute minitest
** Invoke test (first_time)
** Execute test
Robottelo Reporter initialization
Run options: -v --robottelo-reporter --seed 211
# Running:
ExampleTesCase#test_example_1 = 0.00 s = .
ExampleTesCase#test_example_2 = 0.00 s = .
Finished in 0.001410s, 1418.0012 runs/s, 1418.0012 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
Robottelo Reporter build finished: /home/user/projects/Project/test/reports/robottelo/robottelo-results.xml
This will generate one file at test/reports/robottelo/robottelo-results.xml with content

.. code-block:: xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<properties>
</properties>
<testsuite errors="0" failures="0" name="minitest" skips="0" tests="2" time="1.0e-05">
<testcase classname="ExampleTesCase" name="test_example_1" time="1.0e-05">
<testsuite errors="0" failures="0" name="minitest" skips="0" tests="2" time="0.000012">
<testcase classname="ExampleTesCase" name="test_example_1" time="0.000009">
<properties>
<property name="polarion-testcase-id" value="123456"/>
</properties>
</testcase>
<testcase classname="ExampleTesCase" name="test_example_2" time="0.0">
<testcase classname="ExampleTesCase" name="test_example_2" time="0.000003">
<properties>
<property name="polarion-testcase-id" value="123457"/>
</properties>
Expand Down Expand Up @@ -121,13 +146,13 @@ With this variables set The report will looks like
<property name="polarion-custom-variant" value="server"/>
<property name="polarion-custom-plannedin" value="Project_6_3_1_centos7"/>
</properties>
<testsuite errors="0" failures="0" name="minitest" skips="0" tests="2" time="2.0e-05">
<testcase classname="ExampleTesCase" name="test_example_1" time="1.0e-05">
<testsuite errors="0" failures="0" name="minitest" skips="0" tests="2" time="0.000008">
<testcase classname="ExampleTesCase" name="test_example_1" time="0.000006">
<properties>
<property name="polarion-testcase-id" value="123456"/>
</properties>
</testcase>
<testcase classname="ExampleTesCase" name="test_example_2" time="0.0">
<testcase classname="ExampleTesCase" name="test_example_2" time="0.000002">
<properties>
<property name="polarion-testcase-id" value="123457"/>
</properties>
Expand All @@ -148,7 +173,7 @@ In order to change the report name export variable "ROBOTTELO_REPORT_NAME"
$ export ROBOTTELO_REPORT_NAME="other_report_name.xml"
If "CI_REPORTS" environment variable is set the report location will be $CI_REPORTS/robottelo/report_name , where report is the default or custom one.
If "CI_REPORTS" environment variable is set, the report location will be $CI_REPORTS/robottelo/report_name, where report name is the default or custom one.

To set an other location and file name set the report file path

Expand All @@ -158,3 +183,33 @@ To set an other location and file name set the report file path
Note: The Directory will be created automatically if it does no exist


Generate report for one test file:

To generate the report for one test file use the ruby command by adding the --robottelo-reporter option

.. code-block:: bash
$ bundle exec ruby -I"lib:test" test/example_test.rb -v --robottelo-reporter
command output:

.. code-block:: bash
Robottelo Reporter initialization
Run options: -v --robottelo-reporter --seed 39993
# Running:
ExampleTesCase#test_example_1 = 0.00 s = .
ExampleTesCase#test_example_2 = 0.00 s = .
Finished in 0.004316s, 463.3767 runs/s, 463.3767 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
Robottelo Reporter build finished: project_dir/test/reports/robottelo/robottelo-results.xml
and of course the generated report content is the same as above.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
t.test_files = FileList["test/*_test.rb"]
end

task :default do
Expand Down
1 change: 0 additions & 1 deletion lib/minitest/robottelo_reporter_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ def self.plugin_robottelo_reporter_init(options)
return unless options[:robottelo_reporter]
require 'robottelo/reporter'
self.reporter << Robottelo::Reporter::Runner.new
puts 'init robottelo reporter'
end
end
13 changes: 13 additions & 0 deletions lib/robottelo/reporter/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Robottelo
module Reporter
TESTCASE_PROPERTIES_MAPPING = {
pid: 'polarion-testcase-id'
}.freeze
end
PROPERTY_PREFIX = 'polarion'
PROPERTY_PREFIX_CUSTOM = 'polarion-custom'
POLARION_ENV_NAME = 'POLARION_PROPERTIES'
POLARION_CUSTOM_ENV_NAME = 'POLARION_CUSTOM_PROPERTIES'
end
10 changes: 4 additions & 6 deletions lib/robottelo/reporter/polarion.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# frozen_string_literal: true

require 'cgi'
require 'robottelo/reporter/constants'

module Robottelo
module Reporter
POLARION_ENV_NAME = 'POLARION_PROPERTIES'
POLARION_CUSTOM_ENV_NAME = 'POLARION_CUSTOM_PROPERTIES'

class PolarionProperties
attr_reader :properties

Expand Down Expand Up @@ -36,8 +34,8 @@ def parse_env_properties(env_name, prefix)
end

def parse_main_properties
prp = parse_env_properties POLARION_ENV_NAME, 'polarion'
response_key = 'polarion-response'
prp = parse_env_properties POLARION_ENV_NAME, PROPERTY_PREFIX
response_key = "#{PROPERTY_PREFIX}-response"
if prp.key?(response_key)
response_value = prp[response_key].split('=')
prp["#{response_key}-#{response_value[0]}"] = response_value[1] if response_value.length == 2
Expand All @@ -47,7 +45,7 @@ def parse_main_properties
end

def parse_custom_properties
prp = parse_env_properties POLARION_CUSTOM_ENV_NAME, 'polarion-custom'
prp = parse_env_properties POLARION_CUSTOM_ENV_NAME, PROPERTY_PREFIX_CUSTOM
@properties = @properties.merge(prp)
end
end
Expand Down
8 changes: 3 additions & 5 deletions lib/robottelo/reporter/result.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# frozen_string_literal: true

require 'robottelo/reporter/constants'

module Robottelo
module Reporter
TESTCASE_PROPERTIES_MAPPING = {
pid: 'polarion-testcase-id'
}.freeze

TestResult = Struct.new(:klass, :name, :time, :assertions, :failures, :properties) do
def failure
failures.first
Expand Down Expand Up @@ -39,7 +37,7 @@ def failure_to_xml(xml_builder, failure)
end

def to_xml(xml_builder)
xml_builder.testcase(classname: klass, name: name, time: time.round(5)) do
xml_builder.testcase(classname: klass, name: name, time: format('%.6f', time)) do
failure_to_xml xml_builder, failure if failure
properties_to_xml xml_builder
end
Expand Down
2 changes: 1 addition & 1 deletion lib/robottelo/reporter/results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def build
@polarion_properties.to_xml xml_builder
end
xml_builder.testsuite(errors: @errors, failures: @failures, name: 'minitest',
skips: @skips, tests: tests, time: @total_time.round(5)) do
skips: @skips, tests: tests, time: format('%.6f', @total_time)) do
@results.each do |result|
result.to_xml(xml_builder)
end
Expand Down
15 changes: 15 additions & 0 deletions test/example/example_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require 'test/test_helper'

class ExampleTesCase < MinitestWithAttributes
test_attributes pid: '123456'
def test_example_1
assert true
end

test_attributes pid: '123457'
def test_example_2
assert true
end
end
10 changes: 10 additions & 0 deletions test/robottelo_rep_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'test_helper'

class AttributesTest < MinitestWithAttributes
test_attributes pid: '123456', 'title': '123456 attributes'
def test_attributes_binded__to_test_method
assert_equal({pid: '123456', 'title': '123456 attributes'}, AttributesTest.get_test_attributes(name))
end
end
23 changes: 23 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

if RUBY_VERSION > '2.5'
require 'simplecov'
require 'coveralls'

SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter]
SimpleCov.start do
minimum_coverage 70
maximum_coverage_drop 0.1
refuse_coverage_drop
end
end

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)

require 'robottelo/reporter/attributes'
require 'minitest/autorun'

class MinitestWithAttributes < Minitest::Test
extend Robottelo::Reporter::TestAttributes
end

0 comments on commit 46ed950

Please sign in to comment.