Giter VIP home page Giter VIP logo

ninjatrader.unittest's Introduction

NinjaTrader UnitTest

NinjaTrader UnitTest is an add-on for NinjaTrader 8 that provides a unit testing framework similar to Python's unittest, but written in C# and adapted for NinjaTrader.

Installation

To install NinjaTrader.UnitTest, follow these steps:

  1. Download the source code from the GitHub repository.
  2. Build the NinjaTrader.UnitTest.sln solution using Visual Studio to generate the NinjaTrader.UnitTest.dll file.
  3. Copy the NinjaTrader.UnitTest.dll file to the bin/Custom folder of your NinjaTrader 8 installation.
  4. In the NinjaScript Editor, right-click on the References folder and select Add Reference....
  5. In the Add Reference window, browse to the NinjaTrader.UnitTest.dll file and select it.

Usage

To use NinjaTrader.UnitTest in your NinjaScript projects, follow these steps: To use the NinjaTrader UnitTest add-on in your own NinjaScript project, follow these steps:

  1. Add a reference to the NinjaTrader.UnitTest namespace.
  2. Create test cases by subclassing the NinjaTrader.UnitTest.TestCase class.

Here is an example of how to create a simple test case using the NinjaTrader UnitTest add-on:

using System;
using NinjaTrader.UnitTest;

namespace NinjaTrader.NinjaScript.AddOns
{
    public class MyTestCase : TestCase
    {
        public Tests(string name) : base(name)
        { }

        public void TestAddition()
        {
            int result = 2 + 2;
            int expected = 4;
            Assert.AreEqual(expected, result);
        }
    }
}

This code defines a new test case called MyTestCase that contains a single test method called TestAddition. This test method uses the Assert.AreEqual method from the NinjaTrader.UnitTest.Assert class to verify that the result of adding 2 and 2 is equal to 4.

To run this test case, you can create an instance of the MyTestCase class and call its Run method, like this:

MyTestCase myTestCase = new MyTestCase();
myTestCase.Run();

Alternatively, you can create a TestSuite object and add the MyTestCase object to it, like this:

namespace NinjaTrader.NinjaScript.AddOns
{
	public class TestAddon : NinjaTrader.NinjaScript.AddOnBase
	{
		protected override void OnStateChange()
		{
            if (State == State.SetDefaults)
            {
                Name = "TestAddon";
                Description = "An add-on that runs UnitTests on Ninjatrader";
            }
            else if (State == State.Configure)
            {
			
                // Subscribe to connection updates
                Connection.ConnectionStatusUpdate += OnConnectionStatusUpdate;
            }
            else if (State == State.Terminated)
            {
                // Unsubscribe from connection updates
                Connection.ConnectionStatusUpdate -= OnConnectionStatusUpdate;
            }
		}
		
		// This method is fired on connection status update events
        protected void OnConnectionStatusUpdate(object sender, ConnectionStatusEventArgs connectionStatusUpdate)
        {
            if (connectionStatusUpdate.Status == ConnectionStatus.Connected)
            {
                NinjaTrader.NinjaScript.NinjaScript.Log("Connected for orders at " + DateTime.Now, LogLevel.Information);

                // Run tests
                TestSuite suite = new TestSuite();
                suite.Add(new MyTestCase("TestAddition"));
                TestResult result = suite.Run();

                result.PrintSummary();
   
            }

            else if (connectionStatusUpdate.Status == ConnectionStatus.ConnectionLost)
            {
                NinjaTrader.NinjaScript.NinjaScript.Log("Connection for orders lost at: " + DateTime.Now, LogLevel.Information);
            }
        }
	}
}

This will execute the TestAddition method and log the results using the NinjaScript.Log method.

Contributing

We welcome contributions! If you have ideas for improving this tool, please feel free to submit a pull request or open an issue.

License

This project is licensed under the MIT license. See the LICENSE.txt file for more information.

ninjatrader.unittest's People

Contributors

samuelcaldas avatar

Stargazers

MrMkNeo.Lens avatar Mack Hooper avatar  avatar  avatar Zouhir JAABARI avatar  avatar Brian Dowling avatar  avatar Tyler Simpson avatar Brad Demirjian avatar James Craig avatar

Watchers

 avatar  avatar

Forkers

mustaphagawad

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.