https://github.com/shazam/gwen
Library for specifying acceptance criteria in tests in a Given-When-Then format
https://github.com/shazam/gwen
Last synced: about 2 months ago
JSON representation
Library for specifying acceptance criteria in tests in a Given-When-Then format
- Host: GitHub
- URL: https://github.com/shazam/gwen
- Owner: shazam
- Created: 2013-02-25T14:52:23.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2013-10-23T12:40:28.000Z (over 11 years ago)
- Last Synced: 2024-03-26T04:18:03.945Z (about 1 year ago)
- Language: Java
- Size: 227 KB
- Stars: 111
- Watchers: 30
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-java - Gwen - When-Then语法编写验收测试的简单库。 (测试)
README
Gwen
=========
*Gwen* is a simple library that allows writing acceptance tests in a Given-When-Then syntax.Using Gwen, we can transform a very verbose and implementation specific test like this:
```java
public void testNotGonnaTellYou() {
final Instrumentation instrumentation = getInstrumentation();
final Context targetContext = instrumentation.getTargetContext();
File cacheDir = targetContext.getCacheDir();
try {
File file1 = File.createTempFile("file1", "txt", cacheDir);
File file2 = File.createTempFile("file2", "txt", cacheDir);
} catch (IOException e) {
e.printStackTrace();
Assert.fail("Failed to create files " + e.getMessage());
}
Intent intent = new Intent(targetContext, DirectoryBrowserActivity.class);
intent.setData(Uri.parse(cacheDir.getAbsolutePath()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
targetContext.startActivity(intent);
final Solo solo = new Solo(instrumentation);
final boolean file1Displayed = solo.searchText("file1.txt");
final boolean file2Displayed = solo.searchText("file2.txt");
if (!file1Displayed || !file2Displayed) {
Assert.fail("Activity did not display files");
}
}
```into a readable, reusable, extensible and maintainable test like this:
```java
public void testDisplaysDirectoryContents() {
given(directory).contains(SOME_FILES);
when(user).isViewing(directory);
then(user).canSee(THESE_FILES);
}
```License
----Apache v2.0