Guardian667

PineUnit

Guardian667 업데이트됨   
PineUnit by Guardian667

A comprehensive testing framework for Pine Script on TradingView. Built with well-known testing paradigms like Assertions, Units and Suites. It offers the ability to log test results in TradingView's built-in Pine Protocol view, as well as displaying them in a compact table directly on your chart, ensuring your scripts are both robust and reliable.

Unit testing Pine Script indicators, libraries, and strategies becomes seamless, ensuring the precision and dependability of your TradingView scripts. Beyond standard function testing based on predefined input values, PineUnit supports series value testing. This means a test can run on every bar, taking into account its specific values. Moreover, you can specify the exact conditions under which a test should execute, allowing for series-based testing only on bars fitting a designated scenario.

Detailed Guide & Source Code

Quick Start
To get started swiftly with PineUnit, follow this minimalistic example.
import Guardian667/PineUnit/1 as PineUnit

var testSession = PineUnit.createTestSession()
var trueTest = testSession.createSimpleTest("True is always True")
trueTest.assertTrue(true)

testSession.report()
After running your script, you'll notice a table on your chart displaying the test results. For a detailed log output, you can also utilize the Pine Protocol view in TradingView.
--------------------------------------------------------------
T E S T S
--------------------------------------------------------------
Running Default Unit
Tests run: 1, Failures: 0, Not executed: 0, Skipped: 0
To further illustrate, let's introduce a test that's destined to fail:
var bullTest = testSession.createSeriesTest("It's allways Bull Market")
bullTest.assertTrue(close > open, "Uhoh... it's not always bullish")
After executing, the test results will reflect this intentional discrepancy:
--------------------------------------------------------------
T E S T S
--------------------------------------------------------------
Running Default Unit
Tests run: 2, Failures: 1, Not executed: 0, Skipped: 0 <<< FAILURE! - in

It's allways Bull Market
Uhoh... it's not always bullish ==> expected: <true>, but was <false>
This shows how PineUnit efficiently captures and reports discrepancies in test expectations.

It's important to recognise the difference between `createSimpleTest()` and `createSeriesTest()`. In contrast to a simple test, a series-based test is executed on each bar, making assertions on series values.

License
This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0

@ Guardian667

A Personal Note
As a software developer experienced in OO-based languages, diving into Pine Script is a unique journey. While many aspects of it are smooth and efficient, there are also notable gaps, particularly in the realm of testing. We've all been there: using `plotchar()` for debugging, trying to pinpoint those elusive issues in our scripts. I've come to appreciate the value of writing tests, which often obviates the need for such debugging. My hope is that this Testing Framework serves you well and saves you a significant amount of time, more that I invested into developing this "baby."
릴리즈 노트:
v2
Fixed float comparison. Consider two na values as equal
파인 라이브러리

트레이딩뷰 정신에 따라 오써는 이 파인 코드를 오픈 소스 라이브러리로 퍼블리쉬하여 당사 커뮤니티의 다른 파인 프로그래머들이 쓸 수 있도록 하였습니다. 오써에게 찬사를! 여러분은 이 라이브러리를 프라이빗 또는 오픈 소스 퍼블리케이션에 쓸 수 있지만 퍼블리케이션에 재사용은 하우스룰을 따릅니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

이 라이브러리를 쓰시겠습니까?

텍스트를 클립보드에 카피한 뒤 님의 스크립트에 붙여 넣기.