|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Unit Tests & Test-Driven Development
Does anyone know of a sane way to write unit tests for robot code? I'd prefer to have a test-driven development cycle for our code, but I can't think of a good way to implement it for this kind of programming. There's a test harness project on FirstForge here, but it seems to be a dead project. Any ideas?
|
|
#2
|
||||
|
||||
|
Re: Unit Tests & Test-Driven Development
Revive the project
![]() |
|
#3
|
||||
|
||||
|
Re: Unit Tests & Test-Driven Development
Curious if short of emulating the robot like the test-harness project was trying for, does anyone have a nice flow for unit testing bits of logic sans crio that have no robot dependencies?
|
|
#4
|
|||
|
|||
|
Re: Unit Tests & Test-Driven Development
I'd love to revive the project, but I don't think it's appropriate to do during build season.
|
|
#5
|
||||
|
||||
|
Re: Unit Tests & Test-Driven Development
What we created for RobotPy users (python interpreter for cRio) is a library called fake-wpilib, which has bare implementations of most of the WPILib objects. You setup some hooks, import the robot code, and call StartCompetition(), and your unit tests have access to see/control everything.
We have implemented separately a tk-based program that allows our students to run their python robot code in a simulator of sorts, and they can drive the robot around and use sensors and such. If I was re-implementing the test harness again for C++, this is probably how I would go about it. It seems like someone could create a script that could parse the C++ code and automatically create functional shells from that. Tools like SWIG and SIP sorta do that sort of thing, you would just need a mechanism to map function inputs to public variables. |
|
#6
|
||||||
|
||||||
|
Re: Unit Tests & Test-Driven Development
The simplest way is to design your software units for test. What I mean is this: do NOT make any calls to the WPI library from within your unit. Make all calls to WPI library in a wrapper function.
For example: Code:
void periodic_10ms_task(void)
{
armAngle = WPI_readEncoder(ARM_ENCODER);
armLimit = WPI_readDIO(ARM_LIMIT_SWITCH);
armOutput = controlArm(armAngle, armLimit);
WPI_setPWM(armOutput);
}
Now you can test you controlArm() function as a unit on a PC using MS VisualC++ Express. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|