Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
605 views
in Technique[技术] by (71.8m points)

visual-studio-code - 如何在vscode中运行C ++的所有测试用例(How to run all test cases of C++ in vscode)

I am looking for VSCode extension, that runs all the tests I have in my project in one click.

(我正在寻找VSCode扩展,它可以一键运行我在项目中进行的所有测试。)

See the example below, to see what I really mean.

(请参阅下面的示例,以了解我的意思。)

Example

()

Let's say I have a couple of files, that I want to run tests from:

(假设我有几个文件,我想从中运行测试:)

Eg:

(例如:)
1.Test_input_1.txt

(1.Test_input_1.txt)
2.Test_output_1.txt (Correct output for Test_input_1.txt)

(2.Test_output_1.txt(正确的输出为Test_input_1.txt))
3.Test_input_2.txt

(3.Test_input_2.txt)
4.Test_input_3.txt (Correct output for Test_input_1.txt)

(4.Test_input_3.txt(正确的输出为Test_input_1.txt))

Once I click the run button, I want to check my program against all given inputs and outputs.

(单击运行按钮后,我想对照所有给定的输入和输出检查程序。)

Any suggestions are welcomed!

(任何建议都欢迎!)

  ask by bubesh p translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Look s like you have confused two different things.

(看起来您已经混淆了两种不同的事物。)

Quoted example refers to situation where actual tests has been written using some library like: CTest, Google Test, Boost.Test.

(引用的示例是指使用某些库(例如CTest,Google Test,Boost.Test)编写实际测试的情况。)

Using this tools you have to write separate code which tests production code (you can read about TDD - Test driven development).

(使用此工具,您必须编写测试生产代码的单独代码(您可以阅读有关TDD-测试驱动的开发)。)

You have included a list of text files which are feed to standard input using for test cases on sites like: SPOJ, Hackerrank and so on.

(您已经包括了文本文件列表,这些文件可作为标准输入的提要,用于诸如SPOJ,Hackerrank等站点上的测试用例。)

On this sites different programing languages can be used.

(在此站点上可以使用不同的编程语言。)

To verify correctness of provided solution standard input and output is used.

(为了验证所提供解决方案的正确性,使用了标准输入和输出。)

This is a quick simple way to verify correctness of programs created in almost any language, but this solution is not very usable in real life software development.

(这是一种验证几乎所有语言创建的程序正确性的快速简便方法,但是该解决方案在现实生活中的软件开发中不是很有用。)

AFAIK there is no tool which can help you to do it quickly.

(AFAIK没有工具可以帮助您快速完成。)

By refactoring your code you can take advantage of one of the tools and at the same time use those files.

(通过重构代码,您可以利用其中一种工具,同时使用这些文件。)

int problemSolver(std::istream& in, std::ostream& out)
{
}


#ifndef TESTING_MODE
int main()
{
    return problemSolver(std::cin, std::cout);
}
#else

TEST(ProblemSolverTest, input1)
{
    std::istringstream in{ load_file("Test_input_1.txt") };
    std::ostringstream out;

    ASSERT_EQ(problemSolver(in, out), 0);

    auto result = out.str();
    ASSERT_EQ(result, load_file("Test_output_1.txt"));
}

...

#endif // TESTING_MODE

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...