在Eclipse中运行Go测试

在Eclipse中运行Go测试

问题描述:

I have eclipse and goclipse installed, all is well, I can run a console app in the IDE. It is possible to execute the unit tests in the IDE too?

我已经安装了eclipse和goclipse,一切都很好,我可以在IDE中运行控制台应用程序。 也可以在IDE中执行单元测试吗? p> div>

The latest release of goclipse (0.7.6) does provide a means of doing testing using the "testing" package assuming you have followed the project structure recommended in C:/Go/doc/code.html in the installed file structure created when installing Go.

Using the Eclipse "run external tools" button create a new external tool configuration as follows:

  1. on the Main tab the location is C:/Go/bin/go.exe
  2. the argument is test
  3. the working directory should point to the eclipse workspace folder containing the package that is to be tested (eg ${workspace_loc:/goProject/src/pnp}, where pnp is the name of the package NOT the name of the go file that contains the test).

You can now run the test by pressing the Run button in the usual manner, having given the configuration a sensible name eg: go test pnp. You can now add further tests to the package in different go files (or the same one) and all the tests will be carried out in a manner that is expected.

Yes it is if you make a makefile to do so... If you are asking if goclipse has a built in testing facility like JUnit for java the answer is no though.

The issue 5 was asking to "Integrate 'go test' into the IDE and developer workflow."

It now has just been closed (August 2015), with commit 9c3c858 (next release after 0.11.2), with the following documentation:

Each Go project has 3 built-in Build Targets, which are ways in how the project can be built.
These can be viewed and configured in the Project Explorer:

https://raw.githubusercontent.com/GoClipse/goclipse/9c3c8588f49b4d5dfea503c5d39767426a77e791/documentation/screenshots/UserGuide_BuildTargets.png

The modes are:

  • ./... #build: The default build. Builds all Go packages present in the project (excluding test packages).
  • ./... #build-tests: Builds all Go test packages present in the project.
  • ./... #[run-tests]: Builds all and runs Go tests.

Each target can be enabled or disabled when for Eclipse project builds. (There is not much point to have both #build-tests and #[run-tests] enabled though.)