Posts

Showing posts with the label C#

BDD with SpecFlow - Features Scenarios Steps and Contexts

Image
SpecFlow is a tool that bridges the gap between business-level behavior specification and the technical implementations of automated testing. SpecFlow is an acceptance criteria definition and testing tool that makes it easier to integrate Behavior Driven Specifications into software projects earlier, in a shift-left fashion. Business value is defined and modeled as Business Features. Those features are built from more granular components, often called User Stories.  The Feature and User Stories contain sets of Acceptance Criteria that represent the target state for the Feature. The Feature is the top-level construct in Specflow/BDD. Gherkin Business Features are made up of a set of Scenarios.   Each Scenario represents one or more acceptance criteria.  Each SCenario is validated as a single automated unit test or a parameter-driven unit test with a list of parameter sets.  One or more features and their associated scenarios def...

C# IOIO and I2C devices

Image
The IOIO C# library on GitHub now has basic I2C support.  Protocol support and resource management is lifted from the Java library.  The upper API is message based rather than object based. TWI/I2C/SPI is managed via outbound messages. Data from I2C devices and message acknowledgements from the IOIO come back asynchronously via inbound Messages. Hardware This was tested with an IOIO V1, Bluetooth module, a  JeeLabs Expander Plug  and an old Computer power LED.   I2C device The Expander Plug is based on the  MicroChip MCP23008  port expander.  Programming examples are available on the Jee Labs web site. The Microchip web site has the chip programming guide. The LED assembly already had a current limiting resistor. I just plugged it in across the "+" pin on the expansion port and the port pin next to the power pin. The port expander default address is 0x20.  It has 10 registers that control behavior and transfer data. ...

Controlling a Servo attached to an IOIO from Windows WPF application

Image
The IOIO C# library on GitHub now includes a very basic Windows WPF application that lets you control a Servo with your mouse. The program assumes your IOIO is attached to your PC via Bluetooth and that you have a servo on Pin 3. Run the program from inside Visual Studio. Step through the disconnect exception if you run this with debugging enabled.

Message Routing using Double Dispatch with C#

Image
This post describes message routing inside an application. It does not describe message routing across message brokers or across systems. Message driven, or push based notification, systems stream Messages from message sources to interested parties ( Observers) .  There are often multiple message types  routed to multiple observers.  Message types are represented in code as Message interfaces/classes. Message Observers are often interested in some subset of the messages and implement some type of interface or registration scheme that tells the message routing module which message types they are interested in. Scenarios One use case for this is a User Interface that streams UI events (M essages ) from various components to event handlers (O bservers ).  The message sources create messages specific to that event type. The event handlers may receive and process messages of one or more types. Another use case might be some type of IoT device like an IOIO that c...

Extremely Rough Cut at C# based IOIO Library

Image
I've pushed a very rough C# port of the Java IOIO library to GitHub github.com/freemansoft/IOIODotNet/   It communicates with the IOIO as a COM device over Bluetooth. IOIODotNet is a plain old Windows Library. I tried making it a Portable library but .Net portable libraries to don't support Serial devices. The library is a mess of pieces-parts right now with some unit tests that show how it works. There is also a WPF app. Tests and the WPF app poll serial ports to find a Bluetooth attached IOIO. This is a message based API Inbound traffic packed into messages and  routed to inbound handlers. You can add your own or you can poll the ones that exist. Outbound traffic can be sent directly via the API or through a message based API.  I intend that the Message API is the future of the library once resource management has been added. Look at the Integration tests to play with it. They expect at least one IOIO V5xx on a COM port with pins 31 and 32 tied togethe...

log4net configuration with MSTest and Visual Studio 2013

Image
I use log4net because it gives me easy class level control over logging levels and it has a lot of outbound (appender) types.  Folks that dislike log4net will not find this post useful. Visual Studio test output can be pretty confounding. There are way to many forum discussions around viewing test logs in Visual Studio. It sort of makes sense because some of the normal logging channels don't make sense in the test environment.  Phones, web apps, console apps, services all log in different environments.  The Visual Studio team changed the location of the logging views in VS2013 (or possibly 2012). Here is my "how did I do that last time" version of configuring log4net logging for unit tests.   Viewing Test Output Visual studio has an Output  window and an Immediate  window buty my output never shows up in either. I've tried routing the console output to the Immediate  window via the preferences. My output never shows up there. It seems l...

Web Integration and BDD testing with Selenium, Specflow and MSTest

I occasionally participate in a workshop the LitheSpeed folks where we teach Test First Development using standard unit tests and Business Driven Development using Gherkin.  C# and Java developers participate in a mixed class. The first set of labs involves building a library first using developer style unit tests. The second set of labs involves building a library using BDD techniques.  The class wraps up with building a BDD style set of tests against an existing web site. I've created a small shell project on GitHub that contains both a basic Selenium unit test and a basic Specflow driven BDD style Selenium test. This makes it easy to start testing without the overhead of creating a new VS solution.  I built this project in VS2013 which has good NuGet, Specflow and Selenium plugin and Nuget support. The project uses NuGet Package Restore  to pull down the necessary dependencies in an almost Maven like fashion . The Selenium Web Testing development team co...

A quick jni4net performance hack

jni4net is a great library that creates Java proxies for Microsoft based C# libraries on the Windows platform. It makes Java JNI easy with good performance.  You follow this processes to use jni4net Create your C# library Run proxygen to generate Java native library source code and C# adapter source that shims in between Java and the original library. Run javac to compile the java code Create a jar file of the compiled java code Run the .Net csc.exe that comes with the default .Net installation to compile the C# code Create a new DLL of the just compiled C# code Create a Java program that uses the new generated Jar file, the generated C# dll and the original C# dll. I found a quick hack that improves the performance of the jni4net bridge that involves inserting a line of code in each generate C# method. This hack improves the Java-to-DLL call time only.  It does not impact the performance of the Java code on one side or the C# code on the other.  It lowers th...

Java API Wrapper for Windows Performance Counters

Now its time for a quick overview of the Java wrapper API for the Windows Performance Counters. Lifecycle  System Preparation  Library Initialization Counter Caching  Key Retrieval  Counter Usage Time Based Operations Related Posts Lifecycle The lifecycle for these counters is pretty straightforward: System Preparation: creation of counters in the Windows OS. Library Initialization: loading and initializing the library inside your running program Counter caching an optional step that warms up the counter library Key retrieval for any counter you use Counter usage including the API System Preparation You must create any custom counters as Administrator before running any program that uses the Performance Counter system. The simplest way to do this is in a Powershell script because Powershell is available on all modern Windows operating systems.  The following sample script creates a new Category " Freemansoft.JavaTestCategory" and two s...

Recording Java Metrics with the Windows Performance Counters

Image
Example Java Code  Library Performance  Library and Source Code Classspath  CreatingCountersWindowsOperatingSystem  Repository Organization Related Posts Java provides good monitoring through the MBean interface and monitoring tooling. It is nice because it works the same no matter what platform you run on.  There are times when you want to plug into the native performance recording tools especially when running on Windows machines because this makes it easy to integrate your Java application with your Windows based operational consoles. A Java test program generates 2,000,000 performance counter events per second in a single thread and up to 6,500,000 updates per second multi-threaded. (source available on github) This means that counter updates can be made at normal volumes with very little effect on the system. I've created a simple C# library and Java / JNI wrapper that lets you record native Microsoft Windows Performance Counters directly from ...

Windows Performance Counters

Image
Microsoft Windows has a mechanism for recording performance metrics from running applications using the Windows Performance Counters.  This is a high speed system that can be used to gather counts, rats, averages or other numbers based on raw counts or ratios like items/second.  You can see these counters using the perfmon  application.  This system has low overhead and is capable of a high rate of capture. I measured 10 million messages / second  using 4 threads on a 2011 Macbook Pro.  Performance Counters are generated/updated by major system modules and can be extended to include your own modules. Windows 8 comes with over 29,000 standard counters. You can see them by running the typeperf.exe -qx > counterlist.txt.   You can see the Performance counters in action using perfmon. This screen shot shows the  perfmon  application monitoring a cpu performance counter and a custom test performance counter generated by this  c# ...