Skip to content

Commit

Permalink
Merge pull request #36 from rokudev/test
Browse files Browse the repository at this point in the history
v.2.1.0
  • Loading branch information
RokuDevTools authored Mar 21, 2019
2 parents 31707bb + c51fc47 commit 72ba67e
Show file tree
Hide file tree
Showing 33 changed files with 1,351 additions and 288 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# **Roku Unit Testing Framework**
> 01.24.2019
> 03.21.2019
## v.2.1.0

### Features

* Add Initialization mode support to Logger
* Add an ability to choose a test in the Unit Tests
* Add @Ignore test annotation
* Running specific tests in the non-node mode
* Add new channel sample for Selective Test Runs

### Bug Fixes

* AssertEqual was returning false on identical values for some Strings.

## v.2.0.1

Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,31 @@ Every test suite must extend BaseTestSuite and must contain at least one test ca
* For the full instructions, please refer to the [Instructions](https://github.com/rokudev/unit-testing-framework/blob/master/docs/unit-test-framework.md)
* Please send pull requests and feedback to us in this repo.

#### Annotation approach
This is a project to show new approach in building unit tests functions.

It's based on JUnit 5 annotations approach

See [JUnit guide ](https://junit.org/junit5/docs/current/user-guide/)

For now we support

* @Test - describes this is a test
* @BeforeAll - function to run before all functions
* @BeforeEach - function to run before each test execution
* @AfterAll - function that will run after all tests in test suite
* @AfterEach - function that will run after each test
* @RepeatedTest(n) - repeats test for n times
* @ParameterizedTest and @MethodSource("argsProviderFunctionName") - parametrized tests
* @Ignore - function that wont be run as test

#### Local build and run

* clone project and cd to it.
* build a framework, by using: `./build.sh` or `build.bat`
* import built framework to any sample you want (please use `samples` directory)
* run `import_unit_test_framework.bat` or `./import_unit_test_framework.sh` or
place the UnitTestFramework.brs file to the testFramework folder manually.
* please use README.MD from `samples` directory.

_Thanks for building on the Roku Platform!_
318 changes: 224 additions & 94 deletions UnitTestFramework.brs

Large diffs are not rendered by default.

227 changes: 132 additions & 95 deletions docs/unit-test-framework.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function TestSuite__CustomVideoNode__SampleRSGTestSuite() as Object
' Inherite your test suite from BaseTestSuite
' Inherit your test suite from BaseTestSuite
this = BaseTestSuite()

' Test suite name for log statistics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function TestSuite__Hud__SampleRSGTestSuite1() as Object
' Inherite your test suite from BaseTestSuite
' Inherit your test suite from BaseTestSuite
this = BaseTestSuite()

' Test suite name for log statistics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function TestSuite__Hud__SampleRSGTestSuite2() as Object
' Inherite your test suite from BaseTestSuite
' Inherit your test suite from BaseTestSuite
this = BaseTestSuite()

' Test suite name for log statistics
Expand Down
2 changes: 1 addition & 1 deletion samples/RSGTestsExample/source/main.brs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
m.screen = CreateObject("roSGScreen")
m.scene = m.screen.CreateScene("BaseScene")
m.port = CreateObject("roMessagePort")
'getting acess to global node
'getting access to global node
m.global = m.screen.getGlobalNode()

'Set the roMessagePort to be used for all events from the screen.
Expand Down
2 changes: 1 addition & 1 deletion samples/SimpleTestApp/source/main.brs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Function GetApiArray()
rsp = url.GetToString()

'Utility function for XML parsing.
'Bassed on native Bright Script XML parser.
'Based on native Bright Script XML parser.
responseXML = Utils_ParseXML(rsp)
If responseXML <> invalid then
responseXML = responseXML.GetChildElements()
Expand Down
138 changes: 69 additions & 69 deletions samples/SimpleTestApp_Annotation/components/Header.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2017 Roku, Inc. All rights reserved. -->
<!-- Roku Header File -->

<component
name="Header"
extends="Group"
xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">

<interface>
<field type="node" id="ChannelTitle" />
<field type="node" id="CurrentlyPlaying"/>
<field type="node" id="ContentDescription"/>
</interface>

<script type="text/brightscript" uri ="pkg:/components/header.brs"/>

<children>
<Group
id="Header"
translation="[0,100]">
<TwitterLabel
id="ChannelTitle"
width="1920"
height="60"
color="0xFFFFFF"
text="Channel"
translation="[0,20]"
horizAlign="center">
<Font
role="font"
uri="pkg:/fonts/HelveticaNeueLTStd-Roman.otf"
id="HelveticaNeueLTStd-Roman"
size="40" />
</TwitterLabel>
<TwitterLabel
id="CurrentlyPlaying"
width="1250"
height="200"
color="0xFFFFFFFF"
numLines="2"
maxLines="2"
wrap="true"
text="Twitter for Roku"
translation="[350,80]"
horizAlign="center">
<Font
role="font"
uri="pkg:/fonts/HelveticaNeueLTStd-Bd.otf"
id="HelveticaNeueLTStd-Bd"
size="100" />
</TwitterLabel>
<TwitterLabel
id="ContentDescription"
width="1920"
height="60"
color="0xFFFFFF"
text="Watch Live!"
translation="[0,180]"
horizAlign="center">
<Font
role="font"
uri="pkg:/fonts/HelveticaNeueLTStd-Roman.otf"
id="Helvetica-Roman"
size="40" />
</TwitterLabel>
</Group>
</children>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2017 Roku, Inc. All rights reserved. -->
<!-- Roku Header File -->

<component
name="Header"
extends="Group"
xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd">

<interface>
<field type="node" id="ChannelTitle" />
<field type="node" id="CurrentlyPlaying"/>
<field type="node" id="ContentDescription"/>
</interface>

<script type="text/brightscript" uri ="pkg:/components/header.brs"/>

<children>
<Group
id="Header"
translation="[0,100]">
<TwitterLabel
id="ChannelTitle"
width="1920"
height="60"
color="0xFFFFFF"
text="Channel"
translation="[0,20]"
horizAlign="center">
<Font
role="font"
uri="pkg:/fonts/HelveticaNeueLTStd-Roman.otf"
id="HelveticaNeueLTStd-Roman"
size="40" />
</TwitterLabel>
<TwitterLabel
id="CurrentlyPlaying"
width="1250"
height="200"
color="0xFFFFFFFF"
numLines="2"
maxLines="2"
wrap="true"
text="Twitter for Roku"
translation="[350,80]"
horizAlign="center">
<Font
role="font"
uri="pkg:/fonts/HelveticaNeueLTStd-Bd.otf"
id="HelveticaNeueLTStd-Bd"
size="100" />
</TwitterLabel>
<TwitterLabel
id="ContentDescription"
width="1920"
height="60"
color="0xFFFFFF"
text="Watch Live!"
translation="[0,180]"
horizAlign="center">
<Font
role="font"
uri="pkg:/fonts/HelveticaNeueLTStd-Roman.otf"
id="Helvetica-Roman"
size="40" />
</TwitterLabel>
</Group>
</children>
</component>
18 changes: 9 additions & 9 deletions samples/SimpleTestApp_Annotation/components/header.brs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
' Copyright (c) 2017 Roku, Inc. All rights reserved.
' Roku Headers File

' A sub that initialize header
sub header_Init()
m.top.ChannelTitle = m.top.FindNode("ChannelTitle")
m.top.CurrentlyPlaying = m.top.FindNode("CurrentlyPlaying")
m.top.ContentDescription = m.top.FindNode("ContentDescription")
end sub
' Copyright (c) 2017 Roku, Inc. All rights reserved.
' Roku Headers File

' A sub that initialize header
sub header_Init()
m.top.ChannelTitle = m.top.FindNode("ChannelTitle")
m.top.CurrentlyPlaying = m.top.FindNode("CurrentlyPlaying")
m.top.ContentDescription = m.top.FindNode("ContentDescription")
end sub
28 changes: 14 additions & 14 deletions samples/SimpleTestApp_Annotation/manifest
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
title=unit_test_fw_sample
major_version=1
minor_version=1
build_version=0
mm_icon_focus_hd=pkg:/images/MainMenu_Icon_Center_HD.png
mm_icon_focus_sd=pkg:/images/MainMenu_Icon_Center_SD43.png
mm_icon_side_hd=pkg:/images/MainMenu_Icon_Side_HD.png
mm_icon_side_sd=pkg:/images/MainMenu_Icon_Side_SD43.png
splash_screen_fhd=pkg:/images/splash_fhd.jpg
splash_screen_hd=pkg:/images/splash_hd.jpg
splash_screen_sd=pkg:/images/splash_sd.jpg
ui_resolutions=hd
splash_rsg_optimization=1
#rsg_global_namespace=1
title=unit_test_fw_sample
major_version=1
minor_version=1
build_version=0
mm_icon_focus_hd=pkg:/images/MainMenu_Icon_Center_HD.png
mm_icon_focus_sd=pkg:/images/MainMenu_Icon_Center_SD43.png
mm_icon_side_hd=pkg:/images/MainMenu_Icon_Side_HD.png
mm_icon_side_sd=pkg:/images/MainMenu_Icon_Side_SD43.png
splash_screen_fhd=pkg:/images/splash_fhd.jpg
splash_screen_hd=pkg:/images/splash_hd.jpg
splash_screen_sd=pkg:/images/splash_sd.jpg
ui_resolutions=hd
splash_rsg_optimization=1
#rsg_global_namespace=1
#rsg_version=1.2
4 changes: 3 additions & 1 deletion samples/SimpleTestApp_Annotation/source/main.brs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ sub RunUserInterface(args)
screen: screen
}
screen.show()
if true or args.RunTests = "true" and Type(TestRunner) = "Function" then

if args.RunTests = "true" and Type(TestRunner) = "Function" then
Runner = TestRunner()

Runner.SetFunctions([
Expand Down Expand Up @@ -203,6 +204,7 @@ sub RunUserInterface(args)
Test_UTF_assertNotEmpty_negative_invalid_items_parametrized
Test_UTF_assertNotEmpty_negative_invalid_items_with_message_parametrized
])

Runner.Logger.SetVerbosity(3)
Runner.Logger.SetEcho(false)
Runner.Logger.SetJUnit(false)
Expand Down
27 changes: 27 additions & 0 deletions samples/SimpleTestApp_SelectiveRuns/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>SimpleTestApp_SelectiveRuns</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.roku.brightscript.plugin.xml.indexer.RSGComponentsBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.roku.brightscript.ide.eclipse.core.builders.BrightScriptBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.roku.brightscript.ide.eclipse.core.nature</nature>
</natures>
</projectDescription>
28 changes: 28 additions & 0 deletions samples/SimpleTestApp_SelectiveRuns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
1. Run import_unit_test_framework.bat or ./import_unit_test_framework.sh or
place the UnitTestFramework.brs file to the testFramework folder manually.
2. Sideload the app to the box.
3. To run the tests POST the following command to the device via ECP:
http://{Roku_box_IP_address}:8060/launch/dev?RunTests=true

For example: curl -d '' 'http://192.168.0.90:8060/launch/dev?RunTests=true'

Documentation: https://github.com/rokudev/unit-testing-framework

## Overview
This is a project to show new approach in building unit tests functions.

It's based on JUnit 5 annotations approach

See [JUnit guide ](https://junit.org/junit5/docs/current/user-guide/)


For now we support

* @Test - describes this is a test
* @BeforeAll - function to run before all functions
* @BeforeEach - function to run before each test execution
* @AfterAll - function that will run after all tests in test suite
* @AfterEach - function that will run after each test
* @RepeatedTest(n) - repeats test for n times
* @ParameterizedTest and @MethodSource("argsProviderFunctionName") - parametrized tests
* @Ignore - function that wont be run as test
Loading

0 comments on commit 72ba67e

Please sign in to comment.