No Results Found
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.
In the world of software development one of the topics of contention is Module Testing. Some value the approach whilst others see it as worthless. These diametrical opposed views even pervade the world of Safety Critical software development. In these latter organisations, standards such as IEC61508, EN50128 and Def Stan 00-55 usually require (even mandate) the use of module testing. In this context, module testing is just one link in a chain of tools to achieve safe software. However, not everybody is convinced of its benefits and it’s not uncommon for the process of module testing to be applied with a retrospective “ticking the box” approach.
Zircon Software undertakes a range of software services from Requirements, design, implementation and Testing. We are regularly engaged by our clients to carry out module testing both at the time of development and at the latter stages of the programme. So what is module testing?
In recent years the terminology has taken a change with many using the terms Unit Testing, Component Testing or Module Testing interchangeably. But fundamentally it covers the testing of software at its smallest practical chunk, be that a Class, an individual function or a C Module (although definitions do vary). Categories of testing fall into two camps: Black Box testing in which test cases are derived from the specification (or interface) of the module, and White Box testing where test cases are formed from knowledge of the inner workings of the module under test.
Black Box testing typically has the objective to ensure the software module does what the specification defines whilst White Box testing tends to prove no other features are buried inside the piece of code.
Test cases are defined using a multitude of techniques including Boundary Value analysis (bugs like to congregate around the boundary points of data/logic), Equivalence Classes (number_of_engines is not the same as INT32), and Error Guessing (engineers always forget to call the initialisation routine first).
The problem with module testing is that it is an extremely labour intensive and time consuming activity. Often the work is off-shored to low-cost labour countries and the effort to manage the off-shore process and the inevitable wash-dry-repeat nature of the development programme makes managers reluctant to start the process early. Citing reasons of efficiency and the human nature reaction to avoid doing things repeatedly means that managers will delay module testing activities until they are sure ‘nothing will change’.
Referring back for a moment to some of the safety software standards above, it is apparent that they all require a layered approach to testing. Starting with the lowest level Module testing, followed by Integration testing, System testing and finally Acceptance testing. Of course, each layer is aimed at finding different types of bugs, with Module Testing looking for logical and basic functionality, Integration testing focusing on the interaction of modules with each other and System Testing examining performance and timing type issues. This approach can be thought of as a ‘sieving’ process, removing the crudest bugs first and then steadily eradicating more subtle incarnations as it progresses. What this means in practical terms is that the process aims to stamp out the simplest logical, functional and interaction types of bugs BEFORE the system is plugged together.
Why not just test for these bugs at the system level? Well quite simply it’s a matter of time and cost. Remember the ‘Cost of Bugs curve’? This model demonstrates that the cost to find and fix bugs rises by increasing factors as the stage of development progresses. At the module testing stage it’s a small factor (and at the design review stage it’s even smaller!) whilst at the Release stage it may be a factor of ten. The simple fact is that testing on a system rig is an incredibly slow and difficult activity. Often it is very difficult to control the inputs to the system to the minute levels required to isolate a problem. Real time systems have enormous amounts of activity happening simultaneously or in fractions of milliseconds. Furthermore, the ability to ‘see’ into the software, to know what’s going on in this module or that module often, doesn’t exist. This system testing (well actually it’s really debugging) goes into an endless cycle of find, fix and release. Managers begin to tear their hair out as the schedule slips further and further to the right. Costs spiral and confidence in the system evaporates. This back end of the project soon becomes a black hole, sucking in all hands in a desperate attempt to rein in the schedule.
Back in the late nineties and early noughties, Extreme Programming began to take off as a method to improve productivity through improving quality. One element within this was the concept of Test Driven Development. In this approach, the developer writes test cases first and then writes code to ‘pass the test’. The simple idea was to end up with a piece of code that actually did ‘what it said on the tin’. The result of this method meant that, when modules were brought together into an overall system, fewer issues were found during testing. The upside of this led to a much better adherence to project schedules. When we step back and think about this for a moment it’s rather obvious. Less time spent hunting for bugs at the system stage directly equates to a quicker testing phase. The ‘back end’ of the project becomes more predictable as a consequence. Overall the duration of the project is reduced.
Let’s focus on that last statement one more time: If bugs are found earlier the project will cost less because it will be shorter (and more predictable).
So rather than delay module testing it really needs to be performed BEFORE the module is integrated, ideally at the moment the developer has started to write it. Now, with safety based systems often an independent person must perform this testing process. However, there is no reason why this tester cannot begin working with the developer immediately with the sole aim to find and remove bugs at the earliest opportunity and certainly before any code is integrated.
Therefore, delaying module testing or conducting a ‘tick-the-box’ process is actually a false economy.
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.
///////////////////////////////////////////////////////////////////////////
// Preface
//////////
//
// This is a blog about the new version of C++, C++11. It has been many years in the
// making and adds lots of new features to the C++ language. Some of those features
// are already supported by commonly used compilers, a description of these features
// follows.
//
// As you can see, this 'blog' is a bit unusual. It's actually a C++ source code file
// annotated with lots of comments. So it can be read on its own, with the code being
// examples of the things being described, or it can be viewed in Visual Studio (VS)
// 2010, built and even executed. With a few minor adjustments pointed out along the
// way, it can also be built using GCC and executed on whatever system that it is
// installed on.
/////////////////////////////////////////////////////////////////////////////////////////
// Ignore these, I couldn't think of anywhere else to put them.
#include "stdafx.h"
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
/////////////////////////////////////////////////////////////////////////////////////////
// Ruminations on C++11 (the bits currently supported anyway).
//////////////////////////////////////////////////////////////
//
// Of the many new features of C++11, only a subset are available on stable releases of
// the well-used contemporary C++ compilers. I thought that it would be a good exercise
// in understanding these new features to try them out. I decided that I'd try VS2010 on
// Windows 7 and GCC on Ubuntu, as these are easy for me to access and a reasonable
// approximation of other developers environments.
//
// The main differences being there is no support for nullptr in GCC, and no support for
// initialiser lists in VS2010. Of these, the initialiser lists seem the most useful feature, I hope it gets into VS soon.
//
// The features described here are:
// * static_assert
// * trailing return types
// * constructors calling other constructors in the same class
// * lambda functions
// * initialiser lists
// * a fix for the 'std::map< int, std::vector<int>>' '>>' problem
// * 'auto' variable declarations
// * 'decltype' variable declarations
// * rvalue references, move constructors and perfect forwarding
// * nullptr, improved typing for the null pointer value
//
// I have annotated some C++11 code that shows the new features, this code does not fully
// comply with our coding standards in order for the descriptions to be clearer. This
// blog contains code that compiles with VS2010, the GCC supported C++11 features are
// provided in the comments.
// 1. static_assert
///////////////////
//
// First we have an example of 'static_assert', these are compile time assertions. In
// this case, a check is made to ensure that the size of the type used to instantiate the
// object is sufficient. This check occurs at compile time, so the supplied error message
// is displayed as a compile error if the condition is false.
//
template<class T>
class TemplateTest
{
// if the size of the type used to instantiate an object is too small, a compile
// time error is produced.
static_assert( sizeof(T) > 1, "sizeof(T) not > 1!" );
T m_test;
};
// 2. Trailing return type declarations
///////////////////////////////////////
//
// Next up, an example of trailing return types on method declarations.
// If we have a class that defines an enumeration (very handy for code clarity).
class MyEnumClass
{
public:
enum MyHelpfulEnum
{
An,
Enumeration,
That,
Usually,
Helps,
To,
Clarify,
Code
};
MyEnumClass();
MyEnumClass( MyHelpfulEnum initialValue );
// We can declare the method like this, with a trailing return type,
static auto KeepCodeClear() -> MyHelpfulEnum;
// or like this, it makes no difference to the compiler.
//static MyHelpfulEnum KeepCodeClear();
// But I think it is helpful to keep things consistent.
};
// The advantage of this feature comes when declaring the method implementation, as this
// method returns an enumeration defined within the class. Previously you'd have to
// declare the method decorated with lots of scope to help the compiler know what was
// going on (it has enough to contend with without having to deal with this kind of
// thing). Like so,
//
//MyEnumClass::MyHelpfulEnum MyEnumClass::KeepCodeClear()
//
// But now you can declare the method like this.
auto MyEnumClass::KeepCodeClear() -> MyHelpfulEnum
// The '->' is a little different, but less repetition is involved (sort of).
{
// we'll see more from 'auto' later (why keep a keyword for one use when it can
// have three!?)
return Usually;
}
// 3. One constructor calling another
/////////////////////////////////////
//
// Here we have an example of one constructor calling another, I found it annoying that
// this was missing from C++ in the past.
MyEnumClass::MyEnumClass()
{
// this constructor can call another constructor.
MyEnumClass( Helps );
}
MyEnumClass::MyEnumClass( MyHelpfulEnum initialValue )
{
}
// Here are some function prototypes for the nullptr description (something to look
// forward to).
void NullPointerCall( int notAPointerParameter );
void NullPointerCall( int* aPointerParameter );
// 4. Lambda functions
//////////////////////
//
int _tmain(int argc, _TCHAR* argv
[])
{
// Next we have an example of a lambda function (familiar to C# developers). I
// have to admit I'm not a fan of these; if it's a function make it one, at least
// it can be called from other places then. Now I've got that rant out of the way
// we can continue!
//
// If we have a list of interest:
std::vector<int> anInterestingList;
// And that list has some elements, in GCC we can use initialiser lists, like
// so...
//std::vector<int> anInterestingList{1,2,3,4}; // so much nicer.
//
// But for VS we cannot, so add some elements the old fashioned way.
anInterestingList.push_back( 1 );
anInterestingList.push_back( 2 ); // boo
anInterestingList.push_back( 3 );
anInterestingList.push_back( 4 ); // hiss
// Declare an accumulator for our demonstration.
int accumulator( 0 );
// From time to time, it is necessary to loop through all the elements in a list
// (not all that often, but it does happen).
std::for_each( anInterestingList.begin(), anInterestingList.end(),
// Below is the lambda function, the start is defined by '[', the ampersand
// defines the capture list (the variables accessible by the lambda function),
// if the capture list is empty, i.e. there is only '&', all variables in scope
// are available. It seems like good practice to explicitly state what is
// accessible rather than implying everything. If no '&' appears, i.e '[]' is
// used, no variables are captured. There is also, like any other function a
// parameter list.
[&accumulator](int element){ accumulator += element; } );
// the lambda function, accumulates the values in the list.
std::cout << "Accumulator = " << accumulator << std::endl;
// 5. '>>' in variable declarations
///////////////////////////////////
//
// The next feature is more of a fix than anything else. Allowing '>>' in
// declarations. Of course you could always get around this problem by sub
// classing, (or even using typedef, but that's not very OO is it?) but if you did
// do this the error message was, well, ...confusing (I'll leave it at that before
// I say something I shouldn't).
std::map< int, std::vector<int>> lookItWorks;
// It's better to subclass if you can though. This is not a C++11 feature, but I
// rarely see it in C++ and it seems so obviously OO.
class AListOfInts : public std::vector<int>{};
class AMapOfIntvsInts : public std::map< int, AListOfInts>{};
// Of course if you wish to use the constructors of the base classes this method
// is annoying. If only there was a way...
AMapOfIntvsInts anAsideToProceedings;
// Well C++11 allows the use of 'using' to use base class constructors in derived
// classes, which helps this 'problem'. If they were implemented by VS or GCC
// I'd add an example.
// 6. 'auto' types for variable declarations
////////////////////////////////////////////
//
// This very simple extract of code shows another new use of the auto keyword.
// Here you let the compiler automatically deduce the type.
auto autotest( anInterestingList.begin() );
// 7. 'decltype' types for variable declarations
////////////////////////////////////////////////
//
// Similar to the 'auto' type deduction feature above, this time declaring a type
// that is the same as another type.
decltype(autotest) decltypetest(autotest);
// declare decltypetest as the same type as autotest.
std::cout << "*autotest = " << *autotest << std::endl;
std::cout << "*decltypetest = " << *decltypetest << std::endl;
// 8. rvalue references
///////////////////////
//
// As you can only assign lvalues (like variables, objects and other references)
// to references, C++11 introduces rvalue references for the others (like
// temporaries and literals). I'm not going to get into the details here as
// those subjects require whole documents to themselves. So you can have:
int aValue( 9 );
int& myPreferenceIsAReference( aValue );
int& alsoReferingToAValue( myPreferenceIsAReference );
// But you can't have:
// MyEnumClass::MyHelpfulEnum& isTheCodeClear( MyEnumClass::KeepCodeClear() );
// as the return from MyEnumClass::KeepCodeClear() is a temporary variable.
//
// In C++11 using rvalue references you can:
MyEnumClass::MyHelpfulEnum&& isTheCodeClear( MyEnumClass::KeepCodeClear() );
if ( isTheCodeClear == MyEnumClass::Usually )
{
std::cout << "isTheCodeClear == MyEnumClass::Usually, must do better!"
<< std::endl;
}
// You can also do things that seem very strange.
int&& rValueRef = 2;
// assign the rvalue reference to a reference to an rvalue, in this case the
// literal number 2.
++rValueRef;
// Has this blown your mind? We have incremented 2! Surely all that we know and
// love is doomed. It's ok though, as rValueRef is assigned a reference to a
// temporary variable, this is saving time rather than creating a temporary
// and then copying it to a variable.
std::cout << "rValueRef referencing the literal number 2 = "
<< rValueRef << " OMG!" << std::endl;
// These two examples show that less copying of values is attained by using rvalue
// references. The C++11 standard libraries and STL have been written to take
// advantage of this to improve performance without requiring users of these
// libraries to do anything different (apparently). There's lots of talk about
// 'move semantics' and 'perfect forwarding' which is nice if you like that kind
// of thing, these subjects require blogs of their own.
// In summary, they allow less copying, making copy constructors and equals
// operators more efficient. This in turn helps developers to write logical
// code that is far less likely to cause performance issues.
// 1. (again) static_assert
///////////////////////////
//
// static_assert (for compile time assertions). This time we are using the
// static_assert feature to check the sanity of a constant value against another
// constant. This is especially useful to stop people changing constants to
// erroneous values.
const int someConfigValue = 1;
const int someConfigValueCheck = 2;
// As before in the template example, if the condition is false the compiler
// outputs the error text supplied.
static_assert( someConfigValue < someConfigValueCheck,
"someConfigValue is not less than someConfigValueCheck!" );
TemplateTest<int> inttest;
// This is fine, an int passes the static_cast in TemplateTest.
// TemplateTest<bool> booltest;
// This generates a compile time error due to the static cast in the template
// class defined above.
// 9. nullptr
/////////////
//
// nullptr is more strongly typed than 0 or NULL, which helps make things clearer.
// nullptr is not available on GCC at the time of writing so comment out the rest
// of this example to compile with GCC.
int* nullptrtest( nullptr );
if ( nullptrtest == nullptr )
{
// the pointer is null.
std::cout << "The nullptrtest null pointer is set to nullptr."
<< std::endl;
}
// If we don't use nullptr, which function is called for our old null pointer
// values?
NullPointerCall( 0 );
NullPointerCall( NULL );
// If we use nullptr instead things are clearer.
NullPointerCall( nullptr );
// 10. initialiser lists
////////////////////////
//
// This is supported by GCC, but not VS, so I've commented it out. Obviously
// initialiser lists can also be used to pass data to methods. I think this is one
// of the more useful features of C++11, if only for reasons of clarity.
//std::map< int, int> myuselessnumbermap{ { 1,1 }, { 2, 2 } };
// There are many other C++11 features that haven't made it into stable versions
// of either VS or GCC, but now that the standard has been ratified I expect they
// will soon follow. Better enum support, in-class member variable initialisation,
// override control and thread support like thread local storage are all useful
// features, there are many more new features that future compilers will support.
// See http://www2.research.att.com/~bs/C++0xFAQ.html for a description of these
// and the unimplemented C++11 features (aka C++0x, they must've been a bit late).
return 0;
// Literals in code!! Just this one time I'll let myself off (anyway, I've broken
// most of our other coding standards along the way).
}
// These are the implementations of the nullptr description function calls.
void NullPointerCall( int notAPointerParameter )
{
std::cout << "So you'd like me to process your integer?" << std::endl;
}
void NullPointerCall( int* aPointerParameter )
{
std::cout << "So you'd like me to process your pointer?" << std::endl;
}
The page you requested could not be found. Try refining your search, or use the navigation above to locate the post.