C ++如何运行makefile输出

时间:2012-07-30 18:42:05

标签: unit-testing netbeans makefile cppunit

C ++如何运行makefile输出

下面是我的MakeFile,我想问一下如何运行我的unitTest.cpp,因为当我使用NetBean MakeFile时,使用下面的MakeFile,main.exe实际上是main.cpp输出

但我想运行unitTest.cpp的输出

我如何运行unitTest.cpp

# ExampleTests Project

SRCS = main.cpp currencyConverter.cpp unitTest.cpp

HDRS = currencyConverter.h unitTest.h

PROJ = main



# Remaining lines shouldn't need changing

# Here's what they do:

#   - rebuild if any header file or this Makefile changes

#   - include CppUnit as dynamic library

#   - search /opt/local for MacPorts

#   - generate .exe files for Windows

#   - add -enable-auto-import flag for Cygwin only



CC = g++

OBJS = $(SRCS:.cpp=.o)

APP = $(PROJ).exe

CFLAGS = -c -g -Wall -I/opt/local/include

ifeq (,$(findstring CYGWIN,$(shell uname)))

  LDFLAGS = -L/opt/local/lib

else

  LDFLAGS = -L/opt/local/lib -enable-auto-import

endif

LIBS = -lcppunit -ldl



all: $(APP)



$(APP): $(OBJS)

    $(CC) $(LDFLAGS) $(OBJS) -o $(APP) $(LIBS)



%.o: %.cpp $(HDRS)

    $(CC) $(CFLAGS) $< -o $@



clean:

    rm -f *.o $(APP)

以下是我的unitTest.cpp

#include "unitTest.h"
#include "currencyConverter.h"

CPPUNIT_TEST_SUITE_REGISTRATION(unitTest);


unitTest::unitTest() {
}

unitTest::~unitTest() {
}

void unitTest::setUp() {
}

void unitTest::tearDown() {
}

void stringToUpper(string&);

void unitTest::testStringLowerToUpper()
{
string str = "ILOVECPLUSPLUS";
string str2 = "IloveCplusplus";

cout << "\nChecking if string 1 '" << str << "' equals string 2 '" << str2 << "'";
CPPUNIT_ASSERT_EQUAL(str,str2);

//this part i will use my stringToUpperFunction to test.
currencyConverter c;

c.stringToUpper(str2);

cout << "\nChecking if string 1 '" << str << "' equals string 2 '" << str2 << "'";
CPPUNIT_ASSERT_EQUAL(str,str2);

}

1 个答案:

答案 0 :(得分:1)

添加另一个目标(例如testrunner.exe)依赖于您要测试的.cpp文件+您的testsuite .cpp文件+另一个.cpp文件,该文件构成您的testrunner应用程序的main()到您的make文件。有了这个,你可以添加另一个目标测试,取决于只调用testrunner.exe可执行文件的testrunner.exe